protected void writeIndexCommandHeader( WritableChannel channel ) throws IOException { writeIndexCommandHeader( channel, getValueType(), getEntityType(), needsLong( getEntityId() ), startNodeNeedsLong(), endNodeNeedsLong(), getIndexNameId(), getKeyId() ); }
@Override public boolean equals( Object o ) { if ( this == o ) { return true; } if ( o == null || getClass() != o.getClass() ) { return false; } if ( !super.equals( o ) ) { return false; } CreateCommand that = (CreateCommand) o; return Objects.equals( config, that.config ); }
@Override public int hashCode() { return Objects.hash( super.hashCode(), config ); }
writeIndexCommandHeader( channel ); putIntOrLong( channel, getEntityId() ); Object value = getValue(); switch ( getValueType() ) break; default: throw new RuntimeException( "Unknown value type " + getValueType() );
private CommitContext commitContext( IndexCommand command ) throws ExplicitIndexNotFoundKernelException { Map<String,CommitContext> contextMap = commitContextMap( command.getEntityType() ); String indexName = definitions.getIndexName( command.getIndexNameId() ); CommitContext context = contextMap.get( indexName ); if ( context == null ) { IndexIdentifier identifier = new IndexIdentifier( IndexEntityType.byId( command.getEntityType() ), indexName ); // TODO the fact that we look up index type from config here using the index store // directly should be avoided. But how can we do it in, say recovery? // The `dataSource.getType()` call can throw an exception if the index is concurrently deleted. // To avoid bubbling an exception during commit, we instead ignore the commands related to that index, // and proceed as if the index never existed, and thus cannot accept any modifications. IndexType type = dataSource.getType( identifier, recovery ); context = new CommitContext( dataSource, identifier, type, recovery ); contextMap.put( indexName, context ); } return context; }
private boolean visitIndexAddCommand( IndexCommand command, EntityId entityId ) { try { CommitContext context = commitContext( command ); String key = definitions.getKey( command.getKeyId() ); Object value = command.getValue(); // Below is a check for a null value where such a value is ignored. This may look strange, but the // reason is that there was this bug where adding a null value to an index would be fine and written // into the log as a command, to later fail during application of that command, i.e. here. // There was a fix introduced to throw IllegalArgumentException out to user right away if passing in // null or object that had toString() produce null. Although databases already affected by this would // not be able to recover, which is why this check is here. if ( value != null ) { context.ensureWriterInstantiated(); context.indexType.addToDocument( context.getDocument( entityId, true ).document, key, value ); } } catch ( ExplicitIndexNotFoundKernelException ignore ) { // Pretend the index never existed. } return false; }
private void addCommand( String indexName, IndexCommand command, boolean clearFirst ) { List<IndexCommand> commands; if ( command.getEntityType() == IndexEntityType.Node.id() ) { commands = nodeCommands.computeIfAbsent( indexName, k -> new ArrayList<>() ); } else if ( command.getEntityType() == IndexEntityType.Relationship.id() ) { commands = relationshipCommands.computeIfAbsent( indexName, k -> new ArrayList<>() ); } else { throw new IllegalArgumentException( "" + command.getEntityType() ); } if ( clearFirst ) { commands.clear(); } commands.add( command ); }
public void init( int indexNameId, byte entityType, Map<String, String> config ) { super.init( NeoCommandType.INDEX_CREATE_COMMAND, indexNameId, entityType, 0L, (byte)0, null ); this.config = config; }
writeIndexCommandHeader( channel ); putIntOrLong( channel, getEntityId() ); Object value = getValue(); switch ( getValueType() ) break; default: throw new RuntimeException( "Unknown value type " + getValueType() );
String indexName = defineCommand.getIndexName( command.getIndexNameId() ); Map<String,TransactionApplier> applierByIndex = applierByIndexMap( command ); TransactionApplier applier = applierByIndex.get( indexName ); IndexEntityType entityType = IndexEntityType.byId( command.getEntityType() ); Map<String,String> config = indexConfigStore.get( entityType.entityClass(), indexName ); if ( config == null )
private Map<String,TransactionApplier> applierByIndexMap( IndexCommand command ) { if ( command.getEntityType() == IndexEntityType.Node.id() ) { if ( applierByNodeIndex.isEmpty() ) { applierByNodeIndex = new HashMap<>(); lazyCreateApplierByprovider(); } return applierByNodeIndex; } if ( command.getEntityType() == IndexEntityType.Relationship.id() ) { if ( applierByRelationshipIndex.isEmpty() ) { applierByRelationshipIndex = new HashMap<>(); lazyCreateApplierByprovider(); } return applierByRelationshipIndex; } throw new UnsupportedOperationException( "Unknown entity type " + command.getEntityType() ); }
public void init( int indexNameId, byte entityType, long entityId, int keyId, Object value ) { super.init( NeoCommandType.INDEX_REMOVE_COMMAND, indexNameId, entityType, entityId, keyId, value ); }
protected void writeIndexCommandHeader( WritableChannel channel ) throws IOException { writeIndexCommandHeader( channel, getValueType(), getEntityType(), needsLong( getEntityId() ), startNodeNeedsLong(), endNodeNeedsLong(), getIndexNameId(), getKeyId() ); }
String indexName = defineCommand.getIndexName( command.getIndexNameId() ); Map<String,TransactionApplier> applierByIndex = applierByIndexMap( command ); TransactionApplier applier = applierByIndex.get( indexName ); IndexEntityType entityType = IndexEntityType.byId( command.getEntityType() ); Map<String,String> config = indexConfigStore.get( entityType.entityClass(), indexName ); if ( config == null )
private void addCommand( String indexName, IndexCommand command, boolean clearFirst ) { List<IndexCommand> commands; if ( command.getEntityType() == IndexEntityType.Node.id() ) { commands = nodeCommands.computeIfAbsent( indexName, k -> new ArrayList<>() ); } else if ( command.getEntityType() == IndexEntityType.Relationship.id() ) { commands = relationshipCommands.computeIfAbsent( indexName, k -> new ArrayList<>() ); } else { throw new IllegalArgumentException( "" + command.getEntityType() ); } if ( clearFirst ) { commands.clear(); } commands.add( command ); }
public void init( int indexNameId, byte entityType ) { super.init( NeoCommandType.INDEX_DELETE_COMMAND, indexNameId, entityType, 0L, (byte)0, null ); }
@Override public int hashCode() { return Objects.hash( super.hashCode(), startNode, endNode ); }
@Override public boolean equals( Object o ) { if ( this == o ) { return true; } if ( o == null || getClass() != o.getClass() ) { return false; } if ( !super.equals( o ) ) { return false; } AddRelationshipCommand that = (AddRelationshipCommand) o; return startNode == that.startNode && endNode == that.endNode; }
private Map<String,TransactionApplier> applierByIndexMap( IndexCommand command ) { if ( command.getEntityType() == IndexEntityType.Node.id() ) { if ( applierByNodeIndex.isEmpty() ) { applierByNodeIndex = new HashMap<>(); lazyCreateApplierByprovider(); } return applierByNodeIndex; } if ( command.getEntityType() == IndexEntityType.Relationship.id() ) { if ( applierByRelationshipIndex.isEmpty() ) { applierByRelationshipIndex = new HashMap<>(); lazyCreateApplierByprovider(); } return applierByRelationshipIndex; } throw new UnsupportedOperationException( "Unknown entity type " + command.getEntityType() ); }
public void init( int indexNameId, long entityId, int keyId, Object value ) { super.init( NeoCommandType.INDEX_ADD_COMMAND, indexNameId, IndexEntityType.Node.id(), entityId, keyId, value ); }