Search in sources :

Example 1 with TokenHolder

use of org.neo4j.token.api.TokenHolder in project neo4j by neo4j.

the class TestRecoveryScenarios method shouldRecoverCounts.

@Test
void shouldRecoverCounts() throws Exception {
    // GIVEN
    Node node = createNode(label);
    checkPoint();
    deleteNode(node);
    // WHEN
    crashAndRestart();
    // THEN
    // -- really the problem was that recovery threw exception, so mostly assert that.
    Kernel kernel = db.getDependencyResolver().resolveDependency(Kernel.class);
    try (KernelTransaction tx = kernel.beginTransaction(EXPLICIT, LoginContext.AUTH_DISABLED)) {
        assertEquals(0, tx.dataRead().countsForNode(ANY_LABEL));
        final TokenHolder holder = db.getDependencyResolver().resolveDependency(TokenHolders.class).labelTokens();
        int labelId = holder.getIdByName(label.name());
        assertEquals(0, tx.dataRead().countsForNode(labelId));
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Node(org.neo4j.graphdb.Node) TokenHolder(org.neo4j.token.api.TokenHolder) TokenHolders(org.neo4j.token.TokenHolders) Kernel(org.neo4j.kernel.api.Kernel) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with TokenHolder

use of org.neo4j.token.api.TokenHolder in project neo4j by neo4j.

the class RecordLoadingTest method shouldReturnsFalseOnMissingToken.

@Test
void shouldReturnsFalseOnMissingToken() {
    // given
    NodeRecord entity = new NodeRecord(0);
    TokenHolder tokenHolder = new DelegatingTokenHolder(new ReadOnlyTokenCreator(), "Test");
    TokenStore<PropertyKeyTokenRecord> store = mock(TokenStore.class);
    BiConsumer noopReporter = mock(BiConsumer.class);
    // when
    boolean valid = RecordLoading.checkValidToken(entity, 0, tokenHolder, store, noopReporter, noopReporter, CursorContext.NULL);
    // then
    assertFalse(valid);
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) TokenHolder(org.neo4j.token.api.TokenHolder) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) ReadOnlyTokenCreator(org.neo4j.token.ReadOnlyTokenCreator) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord) BiConsumer(java.util.function.BiConsumer) Test(org.junit.jupiter.api.Test)

Example 3 with TokenHolder

use of org.neo4j.token.api.TokenHolder in project neo4j by neo4j.

the class StoreTokens method readOnlyTokenHolders.

/**
 * Create read-only token holders initialised with the tokens from the given {@link NeoStores}.
 * <p>
 * Note that this call will ignore tokens that cannot be loaded due to inconsistencies, rather than throwing an exception.
 * The reason for this is that the read-only token holders are primarily used by tools, such as the consistency checker.
 *
 * @param neoStores The {@link NeoStores} from which to load the initial tokens.
 * @return TokenHolders that can be used for reading tokens, but cannot create new ones.
 */
public static TokenHolders readOnlyTokenHolders(NeoStores neoStores, CursorContext cursorContext) {
    TokenHolder propertyKeyTokens = createReadOnlyTokenHolder(TokenHolder.TYPE_PROPERTY_KEY);
    TokenHolder labelTokens = createReadOnlyTokenHolder(TokenHolder.TYPE_LABEL);
    TokenHolder relationshipTypeTokens = createReadOnlyTokenHolder(TokenHolder.TYPE_RELATIONSHIP_TYPE);
    TokenHolders tokenHolders = new TokenHolders(propertyKeyTokens, labelTokens, relationshipTypeTokens);
    tokenHolders.setInitialTokens(allReadableTokens(neoStores), cursorContext);
    return tokenHolders;
}
Also used : TokenHolder(org.neo4j.token.api.TokenHolder) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) TokenHolders(org.neo4j.token.TokenHolders)

Example 4 with TokenHolder

use of org.neo4j.token.api.TokenHolder in project neo4j by neo4j.

the class RecordStorageEngineFactory method tokenHoldersForSchemaStore.

private static TokenHolders tokenHoldersForSchemaStore(NeoStores stores, TokenCreator propertyKeyTokenCreator, CursorContext cursorContext) {
    TokenHolder propertyKeyTokens = new DelegatingTokenHolder(propertyKeyTokenCreator, TokenHolder.TYPE_PROPERTY_KEY);
    TokenHolders dstTokenHolders = new TokenHolders(propertyKeyTokens, StoreTokens.createReadOnlyTokenHolder(TokenHolder.TYPE_LABEL), StoreTokens.createReadOnlyTokenHolder(TokenHolder.TYPE_RELATIONSHIP_TYPE));
    dstTokenHolders.propertyKeyTokens().setInitialTokens(stores.getPropertyKeyTokenStore().getTokens(cursorContext));
    return dstTokenHolders;
}
Also used : TokenHolder(org.neo4j.token.api.TokenHolder) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) TokenHolders(org.neo4j.token.TokenHolders) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder)

Example 5 with TokenHolder

use of org.neo4j.token.api.TokenHolder in project neo4j by neo4j.

the class GraphStoreFixture method writableTokenHolders.

public TokenHolders writableTokenHolders() {
    TokenHolder propertyKeyTokens = new DelegatingTokenHolder(buildTokenCreator((name, internal, tx, next) -> {
        int id = next.propertyKey();
        tx.propertyKey(id, name, internal);
        return id;
    }), TokenHolder.TYPE_PROPERTY_KEY);
    TokenHolder labelTokens = new DelegatingTokenHolder(buildTokenCreator((name, internal, tx, next) -> {
        int id = next.label();
        tx.nodeLabel(id, name, internal);
        return id;
    }), TokenHolder.TYPE_LABEL);
    TokenHolder relationshipTypeTokens = new DelegatingTokenHolder(buildTokenCreator((name, internal, tx, next) -> {
        int id = next.relationshipType();
        tx.relationshipType(id, name, internal);
        return id;
    }), TokenHolder.TYPE_RELATIONSHIP_TYPE);
    TokenHolders tokenHolders = new TokenHolders(propertyKeyTokens, labelTokens, relationshipTypeTokens);
    tokenHolders.setInitialTokens(allReadableTokens(directStoreAccess().nativeStores()), NULL);
    return tokenHolders;
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt) SchemaRule(org.neo4j.internal.schema.SchemaRule) TokenCreator(org.neo4j.token.TokenCreator) StoreTokens.allReadableTokens(org.neo4j.internal.recordstorage.StoreTokens.allReadableTokens) Preconditions(org.neo4j.util.Preconditions) ThrowingSupplier(org.neo4j.function.ThrowingSupplier) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) IndexStatisticsStore(org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore) NodeLabelsField(org.neo4j.kernel.impl.store.NodeLabelsField) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) LookupAccessorsFromRunningDb(org.neo4j.consistency.LookupAccessorsFromRunningDb) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) Map(java.util.Map) AbstractBaseRecord(org.neo4j.kernel.impl.store.record.AbstractBaseRecord) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) PageCache(org.neo4j.io.pagecache.PageCache) RelationshipGroupDegreesStore(org.neo4j.internal.counts.RelationshipGroupDegreesStore) StorageEngine(org.neo4j.storageengine.api.StorageEngine) IndexProviderMap(org.neo4j.kernel.impl.api.index.IndexProviderMap) SchemaRecord(org.neo4j.kernel.impl.store.record.SchemaRecord) TestDirectory(org.neo4j.test.rule.TestDirectory) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) StandardCharsets(java.nio.charset.StandardCharsets) InternalTransactionCommitProcess(org.neo4j.kernel.impl.api.InternalTransactionCommitProcess) StoragePropertyCursor(org.neo4j.storageengine.api.StoragePropertyCursor) DirectStoreAccess(org.neo4j.consistency.store.DirectStoreAccess) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) RecordStore(org.neo4j.kernel.impl.store.RecordStore) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) StoreType(org.neo4j.kernel.impl.store.StoreType) ANY_LABEL(org.neo4j.internal.kernel.api.TokenRead.ANY_LABEL) NodeStore(org.neo4j.kernel.impl.store.NodeStore) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) CountsStore(org.neo4j.counts.CountsStore) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) TransactionAppender(org.neo4j.kernel.impl.transaction.log.TransactionAppender) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) System.currentTimeMillis(java.lang.System.currentTimeMillis) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) TokenHolder(org.neo4j.token.api.TokenHolder) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) NeoStores(org.neo4j.kernel.impl.store.NeoStores) EntityUpdates(org.neo4j.storageengine.api.EntityUpdates) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) StorageReader(org.neo4j.storageengine.api.StorageReader) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) GraphDatabaseInternalSettings(org.neo4j.configuration.GraphDatabaseInternalSettings) DependencyResolver(org.neo4j.common.DependencyResolver) Iterator(java.util.Iterator) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) Setting(org.neo4j.graphdb.config.Setting) IOException(java.io.IOException) IndexAccessors(org.neo4j.consistency.checking.index.IndexAccessors) PrefetchingIterator(org.neo4j.internal.helpers.collection.PrefetchingIterator) TokenStore(org.neo4j.kernel.impl.store.TokenStore) Neo4jLayout(org.neo4j.io.layout.Neo4jLayout) Consumer(java.util.function.Consumer) CountsAccessor(org.neo4j.counts.CountsAccessor) LongIterator(org.eclipse.collections.api.iterator.LongIterator) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) KernelException(org.neo4j.exceptions.KernelException) TokenHolders(org.neo4j.token.TokenHolders) NamedToken(org.neo4j.token.api.NamedToken) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) CommitEvent(org.neo4j.kernel.impl.transaction.tracing.CommitEvent) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) TokenHolder(org.neo4j.token.api.TokenHolder) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) TokenHolders(org.neo4j.token.TokenHolders) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder)

Aggregations

TokenHolder (org.neo4j.token.api.TokenHolder)6 TokenHolders (org.neo4j.token.TokenHolders)5 DelegatingTokenHolder (org.neo4j.token.DelegatingTokenHolder)4 IOException (java.io.IOException)2 Test (org.junit.jupiter.api.Test)2 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)2 PageCache (org.neo4j.io.pagecache.PageCache)2 NamedToken (org.neo4j.token.api.NamedToken)2 System.currentTimeMillis (java.lang.System.currentTimeMillis)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BiConsumer (java.util.function.BiConsumer)1 Consumer (java.util.function.Consumer)1 Stream (java.util.stream.Stream)1 StringUtils (org.apache.commons.lang3.StringUtils)1 StringUtils.defaultIfEmpty (org.apache.commons.lang3.StringUtils.defaultIfEmpty)1