Uploaded image for project: 'ModeShape'
  1. ModeShape
  2. MODE-2296

Exception when using an index that doesn't contain a search value

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Blocker
    • 4.0.0.Beta2
    • 4.0.0.Beta1
    • Query
    • None

    Description

      I wasn't able to create a neat test case for the problem, what's happening is, I get the following assert exception during one of my tests. I'm not sure if only during tests, but it might be (because of assert statement)

      EDIT: was able to reproduce it, has something to do with joins, see testcase below.

      The assert statement in BufferingSequence fails, If an index is chosen that doesn't contain the search value. But not always, that's why I was unable to create a test case. What I can tell is, that the same Query executes fine, if the search value is present in the index.

      The last trace message prior to the exception is

      5930 TRACE org.modeshape.jcr.index.local.LocalIndexProvider  - Looking for index 'org.erratic.rm.model.RmRole-sysName' in 'local' provider for query in workspace 'default'
      
      at org.modeshape.jcr.query.engine.process.BufferingSequence.<init>(BufferingSequence.java:61)
      	at org.modeshape.jcr.query.engine.process.JoinSequence.<init>(JoinSequence.java:119)
      	at org.modeshape.jcr.query.engine.process.HashJoinSequence.<init>(HashJoinSequence.java:61)
      	at org.modeshape.jcr.query.engine.ScanningQueryEngine.createNodeSequence(ScanningQueryEngine.java:706)
      	at org.modeshape.jcr.query.engine.ScanningQueryEngine.createNodeSequence(ScanningQueryEngine.java:579)
      	at org.modeshape.jcr.query.engine.ScanningQueryEngine.createNodeSequence(ScanningQueryEngine.java:579)
      	at org.modeshape.jcr.query.engine.ScanningQueryEngine.createNodeSequence(ScanningQueryEngine.java:579)
      	at org.modeshape.jcr.query.engine.ScanningQueryEngine.createNodeSequence(ScanningQueryEngine.java:579)
      	at org.modeshape.jcr.query.engine.ScanningQueryEngine.createNodeSequence(ScanningQueryEngine.java:743)
      	at org.modeshape.jcr.query.engine.ScanningQueryEngine.executeOptimizedQuery(ScanningQueryEngine.java:467)
      	at org.modeshape.jcr.query.engine.ScanningQueryEngine.execute(ScanningQueryEngine.java:330)
      	at org.modeshape.jcr.RepositoryQueryManager$1.execute(RepositoryQueryManager.java:171)
      	at org.modeshape.jcr.query.JcrQuery.execute(JcrQuery.java:118)
      	at org.modeshape.jcr.query.JcrQuery.execute(JcrQuery.java:43)
      
      public class WmModeshapeIndex3Test {
      
      	
      	@Inject
      	private Session session;
      
      	@Inject
      	protected transient Logger logger;
      
      	@Test
      	public void test001CheckSomethingWithIndexes() throws RepositoryException, InterruptedException {
      		
      		
      		
      		ensureIndex(indexManager(), "ntusysname", IndexDefinition.IndexKind.VALUE, "local", "nt:unstructured", "", null, "sysName", PropertyType.STRING);
      	
      		Thread.sleep(500);
      		
      		Node newNode2 = session.getRootNode().addNode("XNODE","nt:unstructured");
      		newNode2.setProperty("sysName", "eUser");
      		
      		Thread.sleep(500);
      		
      		Query q = session.getWorkspace().getQueryManager().createQuery("select BASE.* FROM [nt:unstructured] as BASE JOIN [nt:unstructured] AS B ON B.sysName=BASE.sysName WHERE B.sysName=$sysName",Query.JCR_SQL2);
      		q.bindValue("sysName", session.getValueFactory().createValue("eNonexistent"));
      		QueryResult result = q.execute();
      		
      		String plan = ((org.modeshape.jcr.api.query.QueryResult)result).getPlan();
      		logger.info(plan);
      		
      		Assert.assertEquals(true,plan.contains("INDEX_USED=true"));
      	}
      	
      	protected IndexManager indexManager(){
      		
      		if (!(session instanceof org.modeshape.jcr.api.Session)){
      			return null;
      		}
      		
      		try {
      			return ((org.modeshape.jcr.api.Session) session).getWorkspace().getIndexManager();
      		} catch (RepositoryException ex) {
      			logger.error(ex.toString(), ex);
      		}
      		return null;
      	}
      	
      	protected void ensureIndex(IndexManager manager, String indexName, IndexDefinition.IndexKind kind, String providerName, String indexedNodeType, String desc, String workspaceNamePattern, String propertyName, int propertyType) throws RepositoryException {
      
      
      		if (manager.getIndexDefinitions().containsKey(indexName)){
      			return;
      		}
      		
      		logger.info("registering index on property "+propertyName+", type "+indexedNodeType);
      		
      		// Create the index template ...
      		IndexDefinitionTemplate template = manager.createIndexDefinitionTemplate();
      		template.setName(indexName);
      		template.setKind(kind);
      		template.setNodeTypeName(indexedNodeType);
      		template.setProviderName(providerName);
      		if (workspaceNamePattern != null) {
      			template.setWorkspaceNamePattern(workspaceNamePattern);
      		} else {
      			template.setAllWorkspaces();
      		}
      		if (desc != null) {
      			template.setDescription(desc);
      		}
      		
      		// Set up the columns ...
      		IndexColumnDefinition colDefn = manager.createIndexColumnDefinitionTemplate().setPropertyName(propertyName).setColumnType(propertyType);
      		template.setColumnDefinitions(colDefn);
      
      		// Register the index ...
      		manager.registerIndex(template, true);
      	}
      	
      	private void regNodeType(Session repoSession, String typeName) throws RepositoryException{
      			NodeTypeManager mgr = repoSession.getWorkspace().getNodeTypeManager();
      
      			// Create a template for the node type ...
      			NodeTypeTemplate type = mgr.createNodeTypeTemplate();
      			type.setName(typeName);
      			type.setDeclaredSuperTypeNames(new String[]{CrConstants.JCR_NT_UNSTRUCTURED});
      			type.setAbstract(false);
      			type.setOrderableChildNodes(true);
      			type.setMixin(false);
      			type.setQueryable(true);
      			mgr.registerNodeType(type, true);
      	}
      }
      

      Attachments

        Activity

          People

            rhauch Randall Hauch (Inactive)
            bes82 Bjoern Schmidt (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: