Esempio n. 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDropUniquenessConstraintWhereConstraintRecordIsMissingAndIndexHasNoOwner() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
		 public virtual void ShouldDropUniquenessConstraintWhereConstraintRecordIsMissingAndIndexHasNoOwner()
		 {
			  // given
			  using ( Transaction tx = Db.beginTx() )
			  {
					Db.schema().constraintFor(_label).assertPropertyIsUnique(_key).create();
					tx.Success();
			  }

			  // when intentionally breaking the schema by setting the backing index rule to unused
			  RecordStorageEngine storageEngine = Db.DependencyResolver.resolveDependency( typeof( RecordStorageEngine ) );
			  SchemaStore schemaStore = storageEngine.TestAccessNeoStores().SchemaStore;
			  SchemaRule constraintRule = single( filter( rule => rule is ConstraintRule, schemaStore.LoadAllSchemaRules() ) );
			  SetSchemaRecordNotInUse( schemaStore, constraintRule.Id );
			  SchemaRule indexRule = single( filter( rule => rule is StoreIndexDescriptor, schemaStore.LoadAllSchemaRules() ) );
			  SetOwnerNull( schemaStore, ( StoreIndexDescriptor ) indexRule );
			  // At this point the SchemaCache doesn't know about this change so we have to reload it
			  storageEngine.LoadSchemaCache();
			  using ( Transaction tx = Db.beginTx() )
			  {
					// We don't use single() here, because it is okay for the schema cache reload to clean up after us.
					Db.schema().getConstraints(_label).forEach(ConstraintDefinition.drop);
					Db.schema().getIndexes(_label).forEach(IndexDefinition.drop);
					tx.Success();
			  }

			  // then
			  using ( Transaction ignore = Db.beginTx() )
			  {
					assertFalse( Db.schema().Constraints.GetEnumerator().hasNext() );
					assertFalse( Db.schema().Indexes.GetEnumerator().hasNext() );
			  }
		 }
Esempio n. 2
0
 public SchemaRuleCommand(SchemaRecord recordsBefore, SchemaRecord recordsAfter, SchemaRule schemaRule)
 {
     Setup(Iterables.first(recordsAfter).Id, Mode.fromRecordState(Iterables.first(recordsAfter)));
     this.RecordsBeforeConflict = recordsBefore;
     this.RecordsAfterConflict  = recordsAfter;
     this.SchemaRuleConflict    = schemaRule;
 }
Esempio n. 3
0
            internal virtual void AddSchemaRule(SchemaRule rule)
            {
                if (rule is ConstraintRule)
                {
                    ConstraintRule constraintRule = ( ConstraintRule )rule;
                    ConstraintRuleById.put(constraintRule.Id, constraintRule);
                    ConstraintsConflict.Add(ConstraintSemantics.readConstraint(constraintRule));
                }
                else if (rule is StoreIndexDescriptor)
                {
                    CapableIndexDescriptor index = IndexProviderMap.withCapabilities(( StoreIndexDescriptor )rule);
                    IndexDescriptorById.put(index.Id, index);
                    SchemaDescriptor schemaDescriptor = index.Schema();
                    IndexDescriptorsConflict[schemaDescriptor] = index;
                    IndexDescriptorsByName[rule.Name]          = index;
                    foreach (int entityTokenId in schemaDescriptor.EntityTokenIds)
                    {
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
                        ISet <CapableIndexDescriptor> forLabel = IndexDescriptorsByLabel.getIfAbsentPut(entityTokenId, HashSet <object>::new);
                        forLabel.Add(index);
                    }

                    foreach (int propertyId in index.Schema().PropertyIds)
                    {
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
                        IList <CapableIndexDescriptor> indexesForProperty = IndexByProperty.getIfAbsentPut(propertyId, List <object>::new);
                        indexesForProperty.Add(index);
                    }
                }
            }
Esempio n. 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void validateSchemaRule(org.neo4j.storageengine.api.schema.SchemaRule schemaRule) throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException
        public virtual void ValidateSchemaRule(SchemaRule schemaRule)
        {
            if (schemaRule is ConstraintRule)
            {
                ConstraintRule constraintRule = ( ConstraintRule )schemaRule;
                if (constraintRule.ConstraintDescriptor.enforcesUniqueness())
                {
                    try
                    {
                        _indexes.validateIndex(constraintRule.OwnedIndex);
                    }
                    catch (UniquePropertyValueValidationException e)
                    {
                        throw new TransactionFailureException(Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.TransactionValidationFailed, e, "Index validation failed");
                    }
                    catch (Exception e) when(e is IndexNotFoundKernelException || e is IndexPopulationFailedKernelException)
                    {
                        // We don't expect this to occur, and if they do, it is because we are in a very bad state - out of
                        // disk or index corruption, or similar. This will kill the database such that it can be shut down
                        // and have recovery performed. It's the safest bet to avoid loosing data.
                        throw new TransactionFailureException(Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.TransactionValidationFailed, e, "Index population failure");
                    }
                }
            }
        }
Esempio n. 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDropUniquenessConstraintWithBackingIndexHavingNoOwner() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
		 public virtual void ShouldDropUniquenessConstraintWithBackingIndexHavingNoOwner()
		 {
			  // given
			  using ( Transaction tx = Db.beginTx() )
			  {
					Db.schema().constraintFor(_label).assertPropertyIsUnique(_key).create();
					tx.Success();
			  }

			  // when intentionally breaking the schema by setting the backing index rule to unused
			  RecordStorageEngine storageEngine = Db.DependencyResolver.resolveDependency( typeof( RecordStorageEngine ) );
			  SchemaStore schemaStore = storageEngine.TestAccessNeoStores().SchemaStore;
			  SchemaRule indexRule = single( filter( rule => rule is StoreIndexDescriptor, schemaStore.LoadAllSchemaRules() ) );
			  SetOwnerNull( schemaStore, ( StoreIndexDescriptor ) indexRule );
			  // At this point the SchemaCache doesn't know about this change so we have to reload it
			  storageEngine.LoadSchemaCache();
			  using ( Transaction tx = Db.beginTx() )
			  {
					single( Db.schema().getConstraints(_label).GetEnumerator() ).drop();
					tx.Success();
			  }

			  // then
			  using ( Transaction ignore = Db.beginTx() )
			  {
					assertFalse( Db.schema().Constraints.GetEnumerator().hasNext() );
					assertFalse( Db.schema().Indexes.GetEnumerator().hasNext() );
			  }
		 }
Esempio n. 6
0
 internal virtual void CreateSchemaRule(SchemaRule schemaRule)
 {
     foreach (DynamicRecord change in _recordChangeSet.SchemaRuleChanges.create(schemaRule.Id, schemaRule).forChangingData())
     {
         change.InUse = true;
         change.SetCreated();
     }
 }
Esempio n. 7
0
        private void CheckForDuplicates(SchemaRule rule, DynamicRecord record, CheckerEngine <DynamicRecord, Org.Neo4j.Consistency.report.ConsistencyReport_SchemaConsistencyReport> engine)
        {
            DynamicRecord previousContentRecord = _verifiedRulesWithRecords[rule] = record.Clone();

            if (previousContentRecord != null)
            {
                engine.Report().duplicateRuleContent(previousContentRecord);
            }
        }
Esempio n. 8
0
        public static SchemaRuleCommand CreateIndexRule(IndexProviderDescriptor provider, long id, LabelSchemaDescriptor descriptor)
        {
            SchemaRule    rule   = IndexDescriptorFactory.forSchema(descriptor, provider).withId(id);
            DynamicRecord record = new DynamicRecord(id);

            record.InUse = true;
            record.SetCreated();
            record.Data = SchemaRuleSerialization.serialize(rule);
            return(new SchemaRuleCommand(Collections.emptyList(), singletonList(record), rule));
        }
        private ICollection <DynamicRecord> AsRecords(SchemaRule rule, bool inUse)
        {
            // Only used to transfer
            IList <DynamicRecord> records       = new List <DynamicRecord>();
            DynamicRecord         dynamicRecord = new DynamicRecord(rule.Id);

            dynamicRecord.InUse = inUse;
            records.Add(dynamicRecord);
            return(records);
        }
Esempio n. 10
0
        private long StoreRule(SchemaRule rule)
        {
            ICollection <DynamicRecord> records = _store.allocateFrom(rule);

            foreach (DynamicRecord record in records)
            {
                _store.updateRecord(record);
            }
            return(Iterables.first(records).Id);
        }
Esempio n. 11
0
        internal virtual void DropSchemaRule(SchemaRule rule)
        {
            RecordAccess_RecordProxy <SchemaRecord, SchemaRule> change = _recordChangeSet.SchemaRuleChanges.getOrLoad(rule.Id, rule);
            SchemaRecord records = change.ForChangingData();

            foreach (DynamicRecord record in records)
            {
                record.InUse = false;
            }
            records.InUse = false;
        }
Esempio n. 12
0
            //public bool ClearResultRuleList(IDbConnection resultConnection)
            //{
            //    return Hy.Common.Utility.Data.AdoDbHelper.ExecuteSql(resultConnection, "delete from LR_ResultEntryRule");
            //}

            public bool AddVerifiedRule(SchemaRule schemaRule, enumErrorType errType, enumRuleState defaultState)
            {
                string        strObject  = null;
                StringBuilder strBuilder = new StringBuilder("insert into LR_ResultEntryRule(CheckType,RuleInstID,TempInstID,ErrorCount,RuleExeState,TargetFeatClass1,TargetFeatClass2,GZBM,ErrorType) Values ('");

                strObject = schemaRule.ChkTypeName;
                if (strObject == null)
                {
                    strObject = "";
                }
                strBuilder.Append(strObject.Replace("'", "''")); strBuilder.Append("','");

                strObject = schemaRule.arrayRuleParas[0].strInstID;
                if (strObject == null)
                {
                    strObject = "";
                }
                strBuilder.Append(strObject.Replace("'", "''")); strBuilder.Append("','");

                strObject = schemaRule.TempInstID;
                if (strObject == null)
                {
                    strObject = "";
                }
                strBuilder.Append(strObject.Replace("'", "''")); strBuilder.Append("',");

                strBuilder.Append(0); strBuilder.Append(",");
                strBuilder.Append((int)defaultState); strBuilder.Append(",'");

                strObject = schemaRule.FeaClassName;
                if (strObject == null)
                {
                    strObject = "";
                }
                strBuilder.Append(strObject.Replace("'", "''")); strBuilder.Append("','");

                strBuilder.Append("','");


                strObject = schemaRule.arrayRuleParas[0].strGZBM;
                if (strObject == null)
                {
                    strObject = "";
                }
                strBuilder.Append(strObject.Replace("'", "''")); strBuilder.Append("',");

                strBuilder.Append((int)errType);

                strBuilder.Append(")");

                return(Hy.Common.Utility.Data.AdoDbHelper.ExecuteSql(this.m_ResultConnection, strBuilder.ToString()));
            }
Esempio n. 13
0
        private void ChangeSchemaRule(SchemaRule rule, SchemaRule updatedRule)
        {
            //Read the current record
            RecordAccess_RecordProxy <SchemaRecord, SchemaRule> change = _recordChangeSet.SchemaRuleChanges.getOrLoad(rule.Id, rule);
            SchemaRecord records = change.ForReadingData();

            //Register the change of the record
            RecordAccess_RecordProxy <SchemaRecord, SchemaRule> recordChange = _recordChangeSet.SchemaRuleChanges.setRecord(rule.Id, records, updatedRule);
            SchemaRecord dynamicRecords = recordChange.ForChangingData();

            //Update the record
            dynamicRecords.DynamicRecords = _schemaStore.allocateFrom(updatedRule);
        }
Esempio n. 14
0
 public virtual void AddSchemaRule(SchemaRule rule)
 {
     _cacheUpdateLock.@lock();
     try
     {
         SchemaCacheState updatedSchemaState = new SchemaCacheState(_schemaCacheState);
         updatedSchemaState.AddSchemaRule(rule);
         this._schemaCacheState = updatedSchemaState;
     }
     finally
     {
         _cacheUpdateLock.unlock();
     }
 }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static org.neo4j.storageengine.api.schema.SchemaRule deserialize(long id, int labelId, byte kindByte, ByteBuffer buffer) throws org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException
        internal static SchemaRule Deserialize(long id, int labelId, sbyte kindByte, ByteBuffer buffer)
        {
            SchemaRule_Kind kind = SchemaRule_Kind.forId(kindByte);

            try
            {
                SchemaRule rule = NewRule(kind, id, labelId, buffer);
                if (null == rule)
                {
                    throw new MalformedSchemaRuleException(null, "Deserialized null schema rule for id %d with kind %s", id, kind.name());
                }
                return(rule);
            }
            catch (Exception e)
            {
                throw new MalformedSchemaRuleException(e, "Could not deserialize schema rule for id %d with kind %s", id, kind.name());
            }
        }
Esempio n. 16
0
            protected internal override ReturnType fetchNextOrNull()
            {
                while (currentId <= highestId)
                {
                    long id = currentId++;
                    _outerInstance.schemaStore.getRecord(id, record, RecordLoad.FORCE);
                    if (record.inUse() && record.StartRecord)
                    {
                        // It may be that concurrently to our reading there's a transaction dropping the schema rule
                        // that we're reading and that rule may have spanned multiple dynamic records.
                        try
                        {
                            ICollection <DynamicRecord> records;
                            try
                            {
                                records = _outerInstance.schemaStore.getRecords(id, RecordLoad.NORMAL);
                            }
                            catch (InvalidRecordException)
                            {
                                // This may have been due to a concurrent drop of this rule.
                                continue;
                            }

                            SchemaRule schemaRule = SchemaStore.ReadSchemaRule(id, records, scratchData);
                            if (_returnType.IsInstanceOfType(schemaRule))
                            {
                                ReturnType returnRule = _returnType.cast(schemaRule);
                                if (_predicate(returnRule))
                                {
                                    return(returnRule);
                                }
                            }
                        }
                        catch (MalformedSchemaRuleException e)
                        {
                            if (!_ignoreMalformed)
                            {
                                throw new Exception(e);
                            }
                        }
                    }
                }
                return(null);
            }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private Command visitSchemaRuleCommand(org.neo4j.storageengine.api.ReadableChannel channel) throws java.io.IOException
        private Command VisitSchemaRuleCommand(ReadableChannel channel)
        {
            ICollection <DynamicRecord> recordsBefore = new List <DynamicRecord>();

            ReadDynamicRecords(channel, recordsBefore, COLLECTION_DYNAMIC_RECORD_ADDER);
            ICollection <DynamicRecord> recordsAfter = new List <DynamicRecord>();

            ReadDynamicRecords(channel, recordsAfter, COLLECTION_DYNAMIC_RECORD_ADDER);
            sbyte isCreated = channel.Get();

            if (1 == isCreated)
            {
                foreach (DynamicRecord record in recordsAfter)
                {
                    record.SetCreated();
                }
            }
            SchemaRule rule = Iterables.first(recordsAfter).inUse() ? ReadSchemaRule(recordsAfter) : ReadSchemaRule(recordsBefore);

            return(new Command.SchemaRuleCommand(recordsBefore, recordsAfter, rule));
        }
Esempio n. 18
0
        private static void ProcessSchema(SchemaRules schema, ProjectRootElement project)
        {
            if (schema == null)
            {
                throw new ArgumentNullException("schema");
            }
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            foreach (var rules in schema.TypeRulesSet)
            {
                var wrTemplate = new WhereError(rules, schema.Schema);
                ProcessTemplate(wrTemplate, project);

                var rTemplate = new SchemaRule(rules, schema.Schema);
                ProcessTemplate(rTemplate, project);
            }

            var schErrsTmpl = new SchemaErrors(schema);

            ProcessTemplate(schErrsTmpl, project);
        }
Esempio n. 19
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public boolean visitSchemaRuleCommand(Command.SchemaRuleCommand command) throws java.io.IOException
            public override bool VisitSchemaRuleCommand(Command.SchemaRuleCommand command)
            {
                SchemaRule schemaRule = command.SchemaRule;

                if (command.SchemaRule is StoreIndexDescriptor)
                {
                    StoreIndexDescriptor indexRule = ( StoreIndexDescriptor )schemaRule;
                    // Why apply index updates here? Here's the thing... this is a batch applier, which means that
                    // index updates are gathered throughout the batch and applied in the end of the batch.
                    // Assume there are some transactions creating or modifying nodes that may not be covered
                    // by an existing index, but a later transaction in the same batch creates such an index.
                    // In that scenario the index would be created, populated and then fed the [this time duplicate]
                    // update for the node created before the index. The most straight forward solution is to
                    // apply pending index updates up to this point in this batch before index schema changes occur.
                    outerInstance.applyPendingLabelAndIndexUpdates();

                    switch (command.Mode)
                    {
                    case UPDATE:
                        // Shouldn't we be more clear about that we are waiting for an index to come online here?
                        // right now we just assume that an update to index records means wait for it to be online.
                        if (indexRule.CanSupportUniqueConstraint())
                        {
                            // Register activations into the IndexActivator instead of IndexingService to avoid deadlock
                            // that could insue for applying batches of transactions where a previous transaction in the same
                            // batch acquires a low-level commit lock that prevents the very same index population to complete.
                            outerInstance.indexActivator.ActivateIndex(schemaRule.Id);
                        }
                        break;

                    case CREATE:
                        // Add to list so that all these indexes will be created in one call later
                        CreatedIndexes = CreatedIndexes == null ? new List <StoreIndexDescriptor>() : CreatedIndexes;
                        CreatedIndexes.Add(indexRule);
                        break;

                    case DELETE:
                        outerInstance.indexingService.DropIndex(indexRule);
                        outerInstance.indexActivator.IndexDropped(schemaRule.Id);
                        break;

                    default:
                        throw new System.InvalidOperationException(command.Mode.name());
                    }
                }
                // Keep IndexingService updated on constraint changes
                else if (schemaRule is ConstraintRule)
                {
                    ConstraintRule constraintRule = ( ConstraintRule )schemaRule;
                    switch (command.Mode)
                    {
                    case CREATE:
                    case UPDATE:
                        outerInstance.indexingService.PutConstraint(constraintRule);
                        break;

                    case DELETE:
                        outerInstance.indexingService.RemoveConstraint(constraintRule.Id);
                        break;

                    default:
                        throw new System.InvalidOperationException(command.Mode.name());
                    }
                }
                return(false);
            }
Esempio n. 20
0
 public virtual void UpdateSchema(ICollection <DynamicRecord> beforeRecords, ICollection <DynamicRecord> afterRecords, SchemaRule rule)
 {
     foreach (DynamicRecord record in afterRecords)
     {
         record.InUse = true;
     }
     AddSchema(beforeRecords, afterRecords, rule);
 }
Esempio n. 21
0
        // Internals

        private void AddSchema(ICollection <DynamicRecord> beforeRecords, ICollection <DynamicRecord> afterRecords, SchemaRule rule)
        {
            _otherCommands.Add(new Command.SchemaRuleCommand(beforeRecords, afterRecords, rule));
        }
Esempio n. 22
0
 public void CreateSchema(ICollection <DynamicRecord> beforeRecords, ICollection <DynamicRecord> afterRecords, SchemaRule rule)
 {
     Writer.createSchema(beforeRecords, afterRecords, rule);
 }
Esempio n. 23
0
 public SchemaRuleCommand(ICollection <DynamicRecord> recordsBefore, ICollection <DynamicRecord> recordsAfter, SchemaRule schemaRule) : this(new SchemaRecord(recordsBefore), new SchemaRecord(recordsAfter), schemaRule)
 {
 }
Esempio n. 24
0
 public virtual void CreateSchema(ICollection <DynamicRecord> beforeRecord, ICollection <DynamicRecord> afterRecord, SchemaRule rule)
 {
     foreach (DynamicRecord record in afterRecord)
     {
         record.SetCreated();
     }
     UpdateSchema(beforeRecord, afterRecord, rule);
 }
Esempio n. 25
0
 private void CheckSchema(SchemaRule rule, DynamicRecord record, RecordAccess records, CheckerEngine <DynamicRecord, Org.Neo4j.Consistency.report.ConsistencyReport_SchemaConsistencyReport> engine)
 {
     rule.Schema().processWith(new CheckSchema(engine, records));
     CheckForDuplicates(rule, record, engine);
 }