Search in sources :

Example 51 with PropertyKeyTokenRecord

use of org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord in project neo4j by neo4j.

the class NeoStoreTransactionApplierTest method shouldApplyPropertyKeyTokenCommandToTheStoreInRecovery.

@Test
public void shouldApplyPropertyKeyTokenCommandToTheStoreInRecovery() throws Exception {
    // given
    final BatchTransactionApplier applier = newApplier(true);
    final PropertyKeyTokenRecord before = new PropertyKeyTokenRecord(42);
    final PropertyKeyTokenRecord after = new PropertyKeyTokenRecord(42);
    after.setInUse(true);
    after.setNameId(323);
    final Command.PropertyKeyTokenCommand command = new Command.PropertyKeyTokenCommand(before, after);
    final Token token = new Token("token", 21);
    when(propertyKeyTokenStore.getToken((int) command.getKey())).thenReturn(token);
    // when
    boolean result = apply(applier, command::handle, transactionToApply);
    // then
    assertFalse(result);
    verify(propertyKeyTokenStore, times(1)).setHighestPossibleIdInUse(after.getId());
    verify(propertyKeyTokenStore, times(1)).updateRecord(after);
    verify(cacheAccess, times(1)).addPropertyKeyToken(token);
}
Also used : RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) RelationshipTypeToken(org.neo4j.kernel.impl.core.RelationshipTypeToken) Token(org.neo4j.storageengine.api.Token) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) Test(org.junit.Test)

Example 52 with PropertyKeyTokenRecord

use of org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord in project neo4j by neo4j.

the class NeoStoreTransactionApplierTest method shouldApplyPropertyKeyTokenCommandToTheStore.

// PROPERTY KEY TOKEN COMMAND
@Test
public void shouldApplyPropertyKeyTokenCommandToTheStore() throws Exception {
    // given
    final BatchTransactionApplier applier = newApplier(false);
    final PropertyKeyTokenRecord before = new PropertyKeyTokenRecord(42);
    final PropertyKeyTokenRecord after = new PropertyKeyTokenRecord(42);
    after.setInUse(true);
    after.setNameId(323);
    final Command command = new PropertyKeyTokenCommand(before, after);
    // when
    boolean result = apply(applier, command::handle, transactionToApply);
    // then
    assertFalse(result);
    verify(propertyKeyTokenStore, times(1)).updateRecord(after);
}
Also used : RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) Test(org.junit.Test)

Example 53 with PropertyKeyTokenRecord

use of org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord in project neo4j by neo4j.

the class LogTruncationTest method createPropertyKeyTokenRecord.

private PropertyKeyTokenRecord createPropertyKeyTokenRecord(int id) {
    PropertyKeyTokenRecord propertyKeyTokenRecord = new PropertyKeyTokenRecord(id);
    propertyKeyTokenRecord.setInUse(true);
    propertyKeyTokenRecord.setNameId(333);
    propertyKeyTokenRecord.addNameRecord(new DynamicRecord(43));
    return propertyKeyTokenRecord;
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)

Example 54 with PropertyKeyTokenRecord

use of org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord in project neo4j by neo4j.

the class RecordStorageEngineFactory method createMigrationTargetSchemaRuleAccess.

public static SchemaRuleMigrationAccess createMigrationTargetSchemaRuleAccess(NeoStores stores, CursorContext cursorContext, MemoryTracker memoryTracker) {
    SchemaStore dstSchema = stores.getSchemaStore();
    TokenCreator propertyKeyTokenCreator = (name, internal) -> {
        PropertyKeyTokenStore keyTokenStore = stores.getPropertyKeyTokenStore();
        DynamicStringStore nameStore = keyTokenStore.getNameStore();
        byte[] bytes = PropertyStore.encodeString(name);
        List<DynamicRecord> nameRecords = new ArrayList<>();
        AbstractDynamicStore.allocateRecordsFromBytes(nameRecords, bytes, nameStore, cursorContext, memoryTracker);
        nameRecords.forEach(record -> nameStore.prepareForCommit(record, cursorContext));
        nameRecords.forEach(record -> nameStore.updateRecord(record, cursorContext));
        nameRecords.forEach(record -> nameStore.setHighestPossibleIdInUse(record.getId()));
        int nameId = Iterables.first(nameRecords).getIntId();
        PropertyKeyTokenRecord keyTokenRecord = keyTokenStore.newRecord();
        long tokenId = keyTokenStore.nextId(cursorContext);
        keyTokenRecord.setId(tokenId);
        keyTokenRecord.initialize(true, nameId);
        keyTokenRecord.setInternal(internal);
        keyTokenRecord.setCreated();
        keyTokenStore.prepareForCommit(keyTokenRecord, cursorContext);
        keyTokenStore.updateRecord(keyTokenRecord, cursorContext);
        keyTokenStore.setHighestPossibleIdInUse(keyTokenRecord.getId());
        return Math.toIntExact(tokenId);
    };
    TokenHolders dstTokenHolders = tokenHoldersForSchemaStore(stores, propertyKeyTokenCreator, cursorContext);
    return new SchemaRuleMigrationAccessImpl(stores, new SchemaStorage(dstSchema, dstTokenHolders, () -> KernelVersion.LATEST), cursorContext, memoryTracker);
}
Also used : Arrays(java.util.Arrays) Sets.immutable(org.eclipse.collections.api.factory.Sets.immutable) SchemaRule(org.neo4j.internal.schema.SchemaRule) PropertyKeyTokenStore(org.neo4j.kernel.impl.store.PropertyKeyTokenStore) DatabaseReadOnlyChecker.readOnly(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.readOnly) CursorContext(org.neo4j.io.pagecache.context.CursorContext) TokenCreator(org.neo4j.token.TokenCreator) AbstractDynamicStore(org.neo4j.kernel.impl.store.AbstractDynamicStore) Config(org.neo4j.configuration.Config) RecordStoreVersion(org.neo4j.kernel.impl.storemigration.RecordStoreVersion) NullLogProvider(org.neo4j.logging.NullLogProvider) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) ScanOnOpenReadOnlyIdGeneratorFactory(org.neo4j.internal.id.ScanOnOpenReadOnlyIdGeneratorFactory) ConstraintRuleAccessor(org.neo4j.storageengine.api.ConstraintRuleAccessor) ReadOnlyTokenCreator(org.neo4j.token.ReadOnlyTokenCreator) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) LogVersionRepository(org.neo4j.storageengine.api.LogVersionRepository) RecoveryCleanupWorkCollector(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector) Path(java.nio.file.Path) PageCache(org.neo4j.io.pagecache.PageCache) StorageFilesState(org.neo4j.storageengine.api.StorageFilesState) StorageEngine(org.neo4j.storageengine.api.StorageEngine) DatabaseReadOnlyChecker.writable(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) Set(java.util.Set) UUID(java.util.UUID) LockService(org.neo4j.lock.LockService) DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) DbmsReadOnlyChecker(org.neo4j.configuration.helpers.DbmsReadOnlyChecker) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) StoreType(org.neo4j.kernel.impl.store.StoreType) DynamicStringStore(org.neo4j.kernel.impl.store.DynamicStringStore) Optional(java.util.Optional) ServiceProvider(org.neo4j.annotations.service.ServiceProvider) DatabaseReadOnlyChecker(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker) StoreVersion(org.neo4j.storageengine.api.StoreVersion) IdController(org.neo4j.internal.id.IdController) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) RecordStorageMigrator(org.neo4j.kernel.impl.storemigration.RecordStorageMigrator) KernelVersion(org.neo4j.kernel.KernelVersion) LogProvider(org.neo4j.logging.LogProvider) RecordFormatSelector(org.neo4j.kernel.impl.store.format.RecordFormatSelector) ArrayList(java.util.ArrayList) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) TokenHolder(org.neo4j.token.api.TokenHolder) IndexConfigCompleter(org.neo4j.internal.schema.IndexConfigCompleter) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Iterables(org.neo4j.internal.helpers.collection.Iterables) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) StoreId(org.neo4j.storageengine.api.StoreId) JobScheduler(org.neo4j.scheduler.JobScheduler) MemoryTracker(org.neo4j.memory.MemoryTracker) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) SchemaRuleMigrationAccess(org.neo4j.storageengine.migration.SchemaRuleMigrationAccess) RecordFormatSelector.selectForStoreOrConfig(org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForStoreOrConfig) CommandReaderFactory(org.neo4j.storageengine.api.CommandReaderFactory) IdGeneratorMigrator(org.neo4j.kernel.impl.storemigration.IdGeneratorMigrator) RecordFormatSelector.selectForVersion(org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForVersion) IOException(java.io.IOException) StoreMigrationParticipant(org.neo4j.storageengine.migration.StoreMigrationParticipant) DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord) LogService(org.neo4j.logging.internal.LogService) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) MetadataProvider(org.neo4j.storageengine.api.MetadataProvider) RecoveryCleanupWorkCollector.immediate(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.immediate) Collectors.toList(java.util.stream.Collectors.toList) TokenHolders(org.neo4j.token.TokenHolders) StoreVersionCheck(org.neo4j.storageengine.api.StoreVersionCheck) SchemaState(org.neo4j.internal.schema.SchemaState) RecordStoreRollingUpgradeCompatibility(org.neo4j.kernel.impl.storemigration.RecordStoreRollingUpgradeCompatibility) BatchImporterFactory(org.neo4j.internal.batchimport.BatchImporterFactory) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) META_DATA(org.neo4j.kernel.impl.store.StoreType.META_DATA) RecordStoreVersionCheck(org.neo4j.kernel.impl.storemigration.RecordStoreVersionCheck) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) RollingUpgradeCompatibility(org.neo4j.storageengine.migration.RollingUpgradeCompatibility) PropertyKeyTokenStore(org.neo4j.kernel.impl.store.PropertyKeyTokenStore) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) DynamicStringStore(org.neo4j.kernel.impl.store.DynamicStringStore) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) TokenHolders(org.neo4j.token.TokenHolders) TokenCreator(org.neo4j.token.TokenCreator) ReadOnlyTokenCreator(org.neo4j.token.ReadOnlyTokenCreator) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)

Example 55 with PropertyKeyTokenRecord

use of org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord in project neo4j by neo4j.

the class LogCommandSerializationV3_0_10 method readPropertyKeyTokenRecord.

private PropertyKeyTokenRecord readPropertyKeyTokenRecord(int id, ReadableChannel channel) throws IOException {
    // in_use(byte)+count(int)+key_blockId(int)
    byte inUseFlag = channel.get();
    boolean inUse = false;
    if ((inUseFlag & Record.IN_USE.byteValue()) == Record.IN_USE.byteValue()) {
        inUse = true;
    } else if (inUseFlag != Record.NOT_IN_USE.byteValue()) {
        throw new IOException("Illegal in use flag: " + inUseFlag);
    }
    PropertyKeyTokenRecord record = new PropertyKeyTokenRecord(id);
    record.setInUse(inUse);
    record.setPropertyCount(channel.getInt());
    record.setNameId(channel.getInt());
    if (readDynamicRecords(channel, record, PROPERTY_INDEX_DYNAMIC_RECORD_ADDER) == -1) {
        return null;
    }
    return record;
}
Also used : IOException(java.io.IOException) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)

Aggregations

PropertyKeyTokenRecord (org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)65 Test (org.junit.Test)31 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)30 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)28 LabelTokenRecord (org.neo4j.kernel.impl.store.record.LabelTokenRecord)16 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)14 IOException (java.io.IOException)10 SchemaRuleUtil.constraintIndexRule (org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule)8 RecordAccessStub (org.neo4j.consistency.store.RecordAccessStub)8 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)8 NodePropertyDescriptor (org.neo4j.kernel.api.schema.NodePropertyDescriptor)8 IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)8 PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)6 StorageCommand (org.neo4j.storageengine.api.StorageCommand)6 SchemaRuleUtil.uniquenessConstraintRule (org.neo4j.consistency.checking.SchemaRuleUtil.uniquenessConstraintRule)5 NeoStores (org.neo4j.kernel.impl.store.NeoStores)5 ConstraintRule (org.neo4j.kernel.impl.store.record.ConstraintRule)5 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)5 RelationshipTypeTokenRecord (org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord)5 PrimitiveRecord (org.neo4j.kernel.impl.store.record.PrimitiveRecord)4