Search in sources :

Example 6 with TokenHolders

use of org.neo4j.token.TokenHolders in project neo4j by neo4j.

the class IndexPopulationJobTest method before.

@BeforeEach
void before() throws Exception {
    kernel = db.getDependencyResolver().resolveDependency(Kernel.class);
    tokens = db.getDependencyResolver().resolveDependency(TokenNameLookup.class);
    tokenHolders = db.getDependencyResolver().resolveDependency(TokenHolders.class);
    stateHolder = new DatabaseSchemaState(NullLogProvider.getInstance());
    IndexingService indexingService = db.getDependencyResolver().resolveDependency(IndexingService.class);
    indexStoreView = db.getDependencyResolver().resolveDependency(IndexStoreViewFactory.class).createTokenIndexStoreView(indexingService::getIndexProxy);
    indexStatisticsStore = db.getDependencyResolver().resolveDependency(IndexStatisticsStore.class);
    jobScheduler = db.getDependencyResolver().resolveDependency(JobScheduler.class);
    try (KernelTransaction tx = kernel.beginTransaction(IMPLICIT, LoginContext.AUTH_DISABLED)) {
        labelId = tx.tokenWrite().labelGetOrCreateForName(FIRST.name());
        tx.tokenWrite().labelGetOrCreateForName(SECOND.name());
        tx.commit();
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TokenNameLookup(org.neo4j.common.TokenNameLookup) DatabaseSchemaState(org.neo4j.kernel.impl.api.DatabaseSchemaState) IndexStatisticsStore(org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore) TokenHolders(org.neo4j.token.TokenHolders) Kernel(org.neo4j.kernel.api.Kernel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with TokenHolders

use of org.neo4j.token.TokenHolders in project neo4j by neo4j.

the class DatabaseManagementServiceImpl method createDatabase.

@Override
public void createDatabase(String name, Configuration databaseSpecificSettings) {
    String storageEngineName = getStorageEngine(databaseSpecificSettings);
    systemDatabaseExecute("CREATE DATABASE `" + name + "`", (database, transaction) -> {
        // Inject the configured storage engine as a property on the node representing the created database
        // This is somewhat a temporary measure before CREATE DATABASE gets support for specifying the storage engine
        // directly into the command syntax.
        TransactionState txState = ((KernelTransactionImplementation) transaction.kernelTransaction()).txState();
        TokenHolders tokenHolders = database.getDependencyResolver().resolveDependency(TokenHolders.class);
        long nodeId = findNodeForCreatedDatabaseInTransactionState(txState, tokenHolders, name);
        int storageEngineNamePropertyKeyTokenId = tokenHolders.propertyKeyTokens().getOrCreateId(DATABASE_STORAGE_ENGINE_PROPERTY);
        txState.nodeDoAddProperty(nodeId, storageEngineNamePropertyKeyTokenId, Values.stringValue(storageEngineName));
    });
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) TokenHolders(org.neo4j.token.TokenHolders)

Example 8 with TokenHolders

use of org.neo4j.token.TokenHolders 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 9 with TokenHolders

use of org.neo4j.token.TokenHolders in project neo4j by neo4j.

the class KernelTokenTest method setUp.

@BeforeEach
void setUp() {
    ktx = mock(KernelTransactionImplementation.class);
    transactionState = mock(TransactionState.class);
    when(ktx.txState()).thenReturn(transactionState);
    commandCreationContext = mock(CommandCreationContext.class);
    storageReader = mock(StorageReader.class);
    propertyKeyTokens = mock(TokenHolder.class);
    labelTokens = mock(TokenHolder.class);
    relationshipTypeTokens = mock(TokenHolder.class);
    tokenHolders = new TokenHolders(propertyKeyTokens, labelTokens, relationshipTypeTokens);
    kernelToken = new KernelToken(storageReader, commandCreationContext, ktx, tokenHolders);
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) TokenHolder(org.neo4j.token.api.TokenHolder) TokenHolders(org.neo4j.token.TokenHolders) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with TokenHolders

use of org.neo4j.token.TokenHolders 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)

Aggregations

TokenHolders (org.neo4j.token.TokenHolders)22 DelegatingTokenHolder (org.neo4j.token.DelegatingTokenHolder)12 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)10 NeoStores (org.neo4j.kernel.impl.store.NeoStores)9 PageCache (org.neo4j.io.pagecache.PageCache)8 JobScheduler (org.neo4j.scheduler.JobScheduler)8 SchemaRule (org.neo4j.internal.schema.SchemaRule)7 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 Config (org.neo4j.configuration.Config)6 RecoveryCleanupWorkCollector (org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector)6 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)6 TokenHolder (org.neo4j.token.api.TokenHolder)6 Path (java.nio.file.Path)5 DatabaseReadOnlyChecker.writable (org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable)5 PageCacheTracer (org.neo4j.io.pagecache.tracing.PageCacheTracer)5 IndexStatisticsStore (org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore)5 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)5