internal TransactionToRecordStateVisitor(TransactionRecordState recordState, SchemaState schemaState, SchemaStorage schemaStorage, ConstraintSemantics constraintSemantics) { this._recordState = recordState; this._schemaState = schemaState; this._schemaStorage = schemaStorage; this._constraintSemantics = constraintSemantics; }
/// <summary> /// Enters an array value /// </summary> public void EnterArray() { _require(StreamOp.EnterArray); var array = (ArraySchema)_state.Schema; _writer.WriteOpenTag(_state.Tag); _stack.Push(new SchemaState(array, _state.Tag, 0)); _state = new SchemaState(array.ElementType, 255, -1); }
public MultipleIndexPopulator(IndexStoreView storeView, LogProvider logProvider, EntityType type, SchemaState schemaState) { this._storeView = storeView; this._logProvider = logProvider; this.Log = logProvider.GetLog(typeof(IndexPopulationJob)); this._type = type; this._schemaState = schemaState; this._phaseTracker = new LoggingPhaseTracker(logProvider.GetLog(typeof(IndexPopulationJob))); }
/// <summary> /// Leaves an array value /// </summary> public void LeaveArray() { if (_stack.Peek().Schema.Type != Types.ValueType.Array) { throw new InvalidOperationException(); } _state = _stack.Pop(); _writer.WriteCloseTag(_state.Tag); _moveNext(); }
/// <summary> /// Enters a sequence value /// </summary> public void EnterSequence() { _require(StreamOp.EnterSequence); _reader.ReadOpenTag(_state.Tag); var sequence = (SequenceSchema)_state.Schema; var field = sequence.Fields[0]; _stack.Push(new SchemaState(sequence, _state.Tag, 0)); _state = new SchemaState(field.Type, field.Tag, -1); }
/// <summary> /// Enters a choice value /// </summary> /// <param name="choiceIndex">The active choice</param> public void EnterChoice(byte choiceIndex) { _require(StreamOp.EnterChoice); _writer.WriteOpenTag(_state.Tag); var choice = ((ChoiceSchema)_state.Schema); var field = choice.Fields[choiceIndex]; _stack.Push(new SchemaState(choice, _state.Tag, choiceIndex)); _state = new SchemaState(field.Type, field.Tag, -1); }
/// <summary> /// Moves the current state to the next value to read /// </summary> private void _moveNext() { if (_stack.Count == 0) { _state = new SchemaState(PrimitiveSchema.EOF, 255, -1); return; } var parent = _stack.Pop(); if (parent.Schema.Type == Types.ValueType.Option) { // we skip option states on the way back up _moveNext(); } else if (parent.Schema.Type == Types.ValueType.Sequence) { var sequence = (SequenceSchema)parent.Schema; var newParent = new SchemaState(sequence, parent.Tag, parent.Index + 1); if (newParent.Index == sequence.Fields.Length) { // we have read all of fields _state = newParent; } else { // we still have at least 1 field to read _stack.Push(newParent); var field = sequence.Fields[newParent.Index]; _state = new SchemaState(field.Type, field.Tag, -1); } } else if (parent.Schema.Type == Types.ValueType.Choice) { var choice = (ChoiceSchema)parent.Schema; _state = new SchemaState(choice, parent.Tag, choice.Fields.Length); } else if (parent.Schema.Type == Types.ValueType.Array) { var array = (ArraySchema)parent.Schema; var newParent = new SchemaState(array, parent.Tag, parent.Index + 1); _stack.Push(newParent); _state = new SchemaState(array.ElementType, 255, -1); } else { throw new Exception("unknown parent schema state, can't move next"); } }
public RecordStorageEngine(DatabaseLayout databaseLayout, Config config, PageCache pageCache, FileSystemAbstraction fs, LogProvider logProvider, LogProvider userLogProvider, TokenHolders tokenHolders, SchemaState schemaState, ConstraintSemantics constraintSemantics, JobScheduler scheduler, TokenNameLookup tokenNameLookup, LockService lockService, IndexProviderMap indexProviderMap, IndexingService.Monitor indexingServiceMonitor, DatabaseHealth databaseHealth, ExplicitIndexProvider explicitIndexProvider, IndexConfigStore indexConfigStore, IdOrderingQueue explicitIndexTransactionOrdering, IdGeneratorFactory idGeneratorFactory, IdController idController, Monitors monitors, RecoveryCleanupWorkCollector recoveryCleanupWorkCollector, OperationalMode operationalMode, VersionContextSupplier versionContextSupplier) { this._tokenHolders = tokenHolders; this._schemaState = schemaState; this._lockService = lockService; this._databaseHealth = databaseHealth; this._explicitIndexProviderLookup = explicitIndexProvider; this._indexConfigStore = indexConfigStore; this._constraintSemantics = constraintSemantics; this._explicitIndexTransactionOrdering = explicitIndexTransactionOrdering; this._idController = idController; StoreFactory factory = new StoreFactory(databaseLayout, config, idGeneratorFactory, pageCache, fs, logProvider, versionContextSupplier); _neoStores = factory.OpenAllNeoStores(true); try { _schemaCache = new SchemaCache(constraintSemantics, Collections.emptyList(), indexProviderMap); _schemaStorage = new SchemaStorage(_neoStores.SchemaStore); NeoStoreIndexStoreView neoStoreIndexStoreView = new NeoStoreIndexStoreView(lockService, _neoStores); bool readOnly = config.Get(GraphDatabaseSettings.read_only) && operationalMode == OperationalMode.single; monitors.AddMonitorListener(new LoggingMonitor(logProvider.GetLog(typeof(NativeLabelScanStore)))); _labelScanStore = new NativeLabelScanStore(pageCache, databaseLayout, fs, new FullLabelStream(neoStoreIndexStoreView), readOnly, monitors, recoveryCleanupWorkCollector); _indexStoreView = new DynamicIndexStoreView(neoStoreIndexStoreView, _labelScanStore, lockService, _neoStores, logProvider); this._indexProviderMap = indexProviderMap; _indexingService = IndexingServiceFactory.createIndexingService(config, scheduler, indexProviderMap, _indexStoreView, tokenNameLookup, Iterators.asList(_schemaStorage.loadAllSchemaRules()), logProvider, userLogProvider, indexingServiceMonitor, schemaState, readOnly); _integrityValidator = new IntegrityValidator(_neoStores, _indexingService); _cacheAccess = new BridgingCacheAccess(_schemaCache, schemaState, tokenHolders); _explicitIndexApplierLookup = new Org.Neo4j.Kernel.Impl.Api.ExplicitIndexApplierLookup_Direct(explicitIndexProvider); _labelScanStoreSync = new WorkSync <Supplier <LabelScanWriter>, LabelUpdateWork>(_labelScanStore.newWriter); _commandReaderFactory = new RecordStorageCommandReaderFactory(); _indexUpdatesSync = new WorkSync <IndexingUpdateService, IndexUpdatesWork>(_indexingService); _denseNodeThreshold = config.Get(GraphDatabaseSettings.dense_node_threshold); _recordIdBatchSize = config.Get(GraphDatabaseSettings.record_id_batch_size); } catch (Exception failure) { _neoStores.close(); throw failure; } }
/// <summary> /// Optionally enters value /// </summary> /// <param name="hasValue">True if there is a value, false otherwise</param> public void EnterOption(bool hasValue) { _require(StreamOp.Option); if (hasValue) { var option = (OptionSchema)_state.Schema; _stack.Push(_state); _state = new SchemaState(option.ElementType, _state.Tag, -1); } else { _moveNext(); } }
/// <summary> /// Determines whether an option has a value /// </summary> /// <returns>True if the option has a value, false otherwise</returns> public bool OptionHasValue() { _require(StreamOp.Option); // get the expected tag for an option of this type var option = (OptionSchema)_state.Schema; var expected = Utils.GetExpectedTag(_state.Tag, option.ElementType); bool hasValue = _reader.AtTag(expected.ContextTag, expected.ApplicationTag); if (hasValue) { _stack.Push(_state); _state = new SchemaState(option.ElementType, _state.Tag, -1); } else { _moveNext(); } return(hasValue); }
/// <summary> /// Enters a choice value /// </summary> /// <returns>The index of the active choice</returns> public byte EnterChoice() { _require(StreamOp.EnterChoice); _reader.ReadOpenTag(_state.Tag); var choice = ((ChoiceSchema)_state.Schema); for (int i = 0; i < choice.Fields.Length; i++) { var field = choice.Fields[i]; var expected = Utils.GetExpectedTag(field.Tag, field.Type); if (_reader.AtTag(expected.ContextTag, expected.ApplicationTag)) { _stack.Push(new SchemaState(choice, _state.Tag, (byte)i)); _state = new SchemaState(field.Type, field.Tag, -1); return((byte)i); } } throw new UnexpectedTagException(); }
public KernelTransactions(Config config, StatementLocksFactory statementLocksFactory, ConstraintIndexCreator constraintIndexCreator, StatementOperationParts statementOperations, SchemaWriteGuard schemaWriteGuard, TransactionHeaderInformationFactory txHeaderFactory, TransactionCommitProcess transactionCommitProcess, AuxiliaryTransactionStateManager auxTxStateManager, TransactionHooks hooks, TransactionMonitor transactionMonitor, AvailabilityGuard databaseAvailabilityGuard, Tracers tracers, StorageEngine storageEngine, Procedures procedures, TransactionIdStore transactionIdStore, SystemNanoClock clock, AtomicReference <CpuClock> cpuClockRef, AtomicReference <HeapAllocation> heapAllocationRef, AccessCapability accessCapability, AutoIndexing autoIndexing, ExplicitIndexStore explicitIndexStore, VersionContextSupplier versionContextSupplier, CollectionsFactorySupplier collectionsFactorySupplier, ConstraintSemantics constraintSemantics, SchemaState schemaState, IndexingService indexingService, TokenHolders tokenHolders, string currentDatabaseName, Dependencies dataSourceDependencies) { if (!InstanceFieldsInitialized) { InitializeInstanceFields(); InstanceFieldsInitialized = true; } this._config = config; this._statementLocksFactory = statementLocksFactory; this._constraintIndexCreator = constraintIndexCreator; this._statementOperations = statementOperations; this._schemaWriteGuard = schemaWriteGuard; this._transactionHeaderInformationFactory = txHeaderFactory; this._transactionCommitProcess = transactionCommitProcess; this._auxTxStateManager = auxTxStateManager; this._hooks = hooks; this._transactionMonitor = transactionMonitor; this._databaseAvailabilityGuard = databaseAvailabilityGuard; this._tracers = tracers; this._storageEngine = storageEngine; this._procedures = procedures; this._transactionIdStore = transactionIdStore; this._cpuClockRef = cpuClockRef; this._heapAllocationRef = heapAllocationRef; this._accessCapability = accessCapability; this._autoIndexing = autoIndexing; this._explicitIndexStore = explicitIndexStore; this._indexingService = indexingService; this._tokenHolders = tokenHolders; this._currentDatabaseName = currentDatabaseName; this._dataSourceDependencies = dataSourceDependencies; this._versionContextSupplier = versionContextSupplier; this._clock = clock; DoBlockNewTransactions(); this._collectionsFactorySupplier = collectionsFactorySupplier; this._constraintSemantics = constraintSemantics; this._schemaState = schemaState; }
public abstract MultipleIndexPopulator Create(IndexStoreView storeView, LogProvider logProvider, EntityType type, SchemaState schemaState);
/// <summary> /// Constructs a new TagReaderStream /// </summary> /// <param name="reader">The tag reader instance to read from</param> /// <param name="schema">The schema for the types to read</param> public TagReaderStream(TagReader reader, ISchema schema) { this._reader = reader; this._state = new SchemaState(schema, 255, -1); this._stack = new Stack <SchemaState>(4); }
public static IndexingService CreateIndexingService(Config config, JobScheduler scheduler, IndexProviderMap providerMap, IndexStoreView storeView, TokenNameLookup tokenNameLookup, IEnumerable <SchemaRule> schemaRules, LogProvider internalLogProvider, LogProvider userLogProvider, IndexingService.Monitor monitor, SchemaState schemaState, bool readOnly) { IndexSamplingConfig samplingConfig = new IndexSamplingConfig(config); MultiPopulatorFactory multiPopulatorFactory = MultiPopulatorFactory.ForConfig(config); IndexMapReference indexMapRef = new IndexMapReference(); IndexSamplingControllerFactory factory = new IndexSamplingControllerFactory(samplingConfig, storeView, scheduler, tokenNameLookup, internalLogProvider); IndexSamplingController indexSamplingController = factory.Create(indexMapRef); IndexProxyCreator proxySetup = new IndexProxyCreator(samplingConfig, storeView, providerMap, tokenNameLookup, internalLogProvider); return(new IndexingService(proxySetup, providerMap, indexMapRef, storeView, schemaRules, indexSamplingController, tokenNameLookup, scheduler, schemaState, multiPopulatorFactory, internalLogProvider, userLogProvider, monitor, readOnly)); }
/// <summary> /// Moves the current state to the next value to read /// </summary> private void _moveNext() { if (_stack.Count == 0) { _state = new SchemaState(PrimitiveSchema.EOF, 255, -1); return; } var parent = _stack.Pop(); if (parent.Schema.Type == Types.ValueType.Option) { // we skip option states on the way back up _moveNext(); } else if (parent.Schema.Type == Types.ValueType.Sequence) { var sequence = (SequenceSchema)parent.Schema; var newParent = new SchemaState(sequence, parent.Tag, parent.Index + 1); if (newParent.Index == sequence.Fields.Length) { // we have read all of fields _state = newParent; } else { // we still have at least 1 field to read _stack.Push(newParent); var field = sequence.Fields[newParent.Index]; _state = new SchemaState(field.Type, field.Tag, -1); } } else if (parent.Schema.Type == Types.ValueType.Choice) { var choice = (ChoiceSchema)parent.Schema; _state = new SchemaState(choice, parent.Tag, choice.Fields.Length); } else if (parent.Schema.Type == Types.ValueType.Array) { var array = (ArraySchema)parent.Schema; var newParent = new SchemaState(array, parent.Tag, parent.Index + 1); _stack.Push(newParent); _state = new SchemaState(array.ElementType, 255, -1); } else throw new Exception("unknown parent schema state, can't move next"); }
/// <summary> /// Determines whether an option has a value /// </summary> /// <returns>True if the option has a value, false otherwise</returns> public bool OptionHasValue() { _require(StreamOp.Option); // get the expected tag for an option of this type var option = (OptionSchema)_state.Schema; var expected = Utils.GetExpectedTag(_state.Tag, option.ElementType); bool hasValue = _reader.AtTag(expected.ContextTag, expected.ApplicationTag); if(hasValue) { _stack.Push(_state); _state = new SchemaState(option.ElementType, _state.Tag, -1); } else { _moveNext(); } return hasValue; }
/// <summary> /// Constructs a new TagWriterSink /// </summary> /// <param name="writer">The tag writer instance to write to</param> /// <param name="schema">The schema for the types to write</param> public TagWriterSink(TagWriter writer, ISchema schema) { this._writer = writer; this._state = new SchemaState(schema, 255, -1); this._stack = new Stack <SchemaState>(4); }
/// <summary> /// Leaves an array value /// </summary> public void LeaveArray() { if (_stack.Peek().Schema.Type != Types.ValueType.Array) throw new InvalidOperationException(); _state = _stack.Pop(); _writer.WriteCloseTag(_state.Tag); _moveNext(); }
/// <summary> /// Creates a new multi-threaded populator for the given store view. </summary> /// <param name="storeView"> the view of the store as a visitable of nodes </param> /// <param name="logProvider"> the log provider </param> /// <param name="type"> entity type to populate </param> /// <param name="schemaState"> the schema state </param> internal BatchingMultipleIndexPopulator(IndexStoreView storeView, LogProvider logProvider, EntityType type, SchemaState schemaState) : base(storeView, logProvider, type, schemaState) { if (!InstanceFieldsInitialized) { InitializeInstanceFields(); InstanceFieldsInitialized = true; } this._executor = CreateThreadPool(); }
/// <summary> /// Creates a new multi-threaded populator with the specified thread pool. /// <para> /// <b>NOTE:</b> for testing only. /// /// </para> /// </summary> /// <param name="storeView"> the view of the store as a visitable of nodes </param> /// <param name="executor"> the thread pool to use for batched index insertions </param> /// <param name="logProvider"> the log provider </param> /// <param name="schemaState"> the schema state </param> internal BatchingMultipleIndexPopulator(IndexStoreView storeView, ExecutorService executor, LogProvider logProvider, SchemaState schemaState) : base(storeView, logProvider, EntityType.NODE, schemaState) { if (!InstanceFieldsInitialized) { InitializeInstanceFields(); InstanceFieldsInitialized = true; } this._executor = executor; }
/// <summary> /// Moves the current state to the next value to read /// </summary> private void _moveNext() { if (_stack.Count == 0) { _state = new SchemaState(PrimitiveSchema.EOF, 255, -1); return; } var parent = _stack.Pop(); if (parent.Schema.Type == Types.ValueType.Option) { // we skip option states on the way back up _moveNext(); } else if (parent.Schema.Type == Types.ValueType.Sequence) { var sequence = (SequenceSchema)parent.Schema; var newParent = new SchemaState(sequence, parent.Tag, parent.Index + 1); if (newParent.Index == sequence.Fields.Length) { // we have read all of fields _state = newParent; } else { // we still have at least 1 field to read _stack.Push(newParent); var field = sequence.Fields[newParent.Index]; _state = new SchemaState(field.Type, field.Tag, -1); } } else if (parent.Schema.Type == Types.ValueType.Choice) { var choice = (ChoiceSchema)parent.Schema; _state = new SchemaState(choice, parent.Tag, choice.Fields.Length); } else if (parent.Schema.Type == Types.ValueType.Array) { var array = (ArraySchema)parent.Schema; // TODO: Might still need better logic for detecting // whether we are at the end of the array if (_reader.EOF()) { _state = new SchemaState(array, parent.Tag, parent.Index + 1); } else if (array.ElementType == PrimitiveSchema.GenericSchema) { if (_reader.AtTag(parent.Tag, ApplicationTag.Null)) { _state = new SchemaState(array, parent.Tag, parent.Index + 1); } else { var newParent = new SchemaState(array, parent.Tag, parent.Index + 1); _stack.Push(newParent); _state = new SchemaState(array.ElementType, 255, -1); } } else { var elementExpected = Utils.GetExpectedTag(255, array.ElementType); if (_reader.AtTag(elementExpected.ContextTag, elementExpected.ApplicationTag)) { var newParent = new SchemaState(array, parent.Tag, parent.Index + 1); _stack.Push(newParent); _state = new SchemaState(array.ElementType, 255, -1); } else { _state = new SchemaState(array, parent.Tag, parent.Index + 1); } } } else { throw new Exception("unknown parent schema state, can't move next"); } }
/// <summary> /// Enters a choice value /// </summary> /// <returns>The index of the active choice</returns> public byte EnterChoice() { _require(StreamOp.EnterChoice); _reader.ReadOpenTag(_state.Tag); var choice = ((ChoiceSchema)_state.Schema); for(int i = 0; i < choice.Fields.Length; i++) { var field = choice.Fields[i]; var expected = Utils.GetExpectedTag(field.Tag, field.Type); if (_reader.AtTag(expected.ContextTag, expected.ApplicationTag)) { _stack.Push(new SchemaState(choice, _state.Tag, (byte)i)); _state = new SchemaState(field.Type, field.Tag, -1); return (byte)i; } } throw new UnexpectedTagException(); }
public override MultipleIndexPopulator Create(IndexStoreView storeView, LogProvider logProvider, EntityType type, SchemaState schemaState) { return(new BatchingMultipleIndexPopulator(storeView, logProvider, type, schemaState)); }
/// <summary> /// Constructs a new TagReaderStream /// </summary> /// <param name="reader">The tag reader instance to read from</param> /// <param name="schema">The schema for the types to read</param> public TagReaderStream(TagReader reader, ISchema schema) { this._reader = reader; this._state = new SchemaState(schema, 255, -1); this._stack = new Stack<SchemaState>(4); }
/// <summary> /// Constructs a new TagWriterSink /// </summary> /// <param name="writer">The tag writer instance to write to</param> /// <param name="schema">The schema for the types to write</param> public TagWriterSink(TagWriter writer, ISchema schema) { this._writer = writer; this._state = new SchemaState(schema, 255, -1); this._stack = new Stack<SchemaState>(4); }
/// <summary> /// Moves the current state to the next value to read /// </summary> private void _moveNext() { if(_stack.Count == 0) { _state = new SchemaState(PrimitiveSchema.EOF, 255, -1); return; } var parent = _stack.Pop(); if (parent.Schema.Type == Types.ValueType.Option) { // we skip option states on the way back up _moveNext(); } else if (parent.Schema.Type == Types.ValueType.Sequence) { var sequence = (SequenceSchema)parent.Schema; var newParent = new SchemaState(sequence, parent.Tag, parent.Index + 1); if (newParent.Index == sequence.Fields.Length) { // we have read all of fields _state = newParent; } else { // we still have at least 1 field to read _stack.Push(newParent); var field = sequence.Fields[newParent.Index]; _state = new SchemaState(field.Type, field.Tag, -1); } } else if (parent.Schema.Type == Types.ValueType.Choice) { var choice = (ChoiceSchema)parent.Schema; _state = new SchemaState(choice, parent.Tag, choice.Fields.Length); } else if (parent.Schema.Type == Types.ValueType.Array) { var array = (ArraySchema)parent.Schema; // TODO: Might still need better logic for detecting // whether we are at the end of the array if (_reader.EOF()) { _state = new SchemaState(array, parent.Tag, parent.Index + 1); } else if (array.ElementType == PrimitiveSchema.GenericSchema) { if (_reader.AtTag(parent.Tag, ApplicationTag.Null)) { _state = new SchemaState(array, parent.Tag, parent.Index + 1); } else { var newParent = new SchemaState(array, parent.Tag, parent.Index + 1); _stack.Push(newParent); _state = new SchemaState(array.ElementType, 255, -1); } } else { var elementExpected = Utils.GetExpectedTag(255, array.ElementType); if (_reader.AtTag(elementExpected.ContextTag, elementExpected.ApplicationTag)) { var newParent = new SchemaState(array, parent.Tag, parent.Index + 1); _stack.Push(newParent); _state = new SchemaState(array.ElementType, 255, -1); } else { _state = new SchemaState(array, parent.Tag, parent.Index + 1); } } } else throw new Exception("unknown parent schema state, can't move next"); }
internal TrackingMultipleIndexPopulator(IndexStoreView storeView, LogProvider logProvider, EntityType type, SchemaState schemaState) : base(storeView, logProvider, type, schemaState) { }