use of org.neo4j.token.DelegatingTokenHolder in project neo4j by neo4j.
the class RecordStorageReaderTestBase method before.
@BeforeEach
public void before() throws Throwable {
this.tokenHolders = new TokenHolders(new DelegatingTokenHolder(new SimpleTokenCreator(), TokenHolder.TYPE_PROPERTY_KEY), new DelegatingTokenHolder(new SimpleTokenCreator(), TokenHolder.TYPE_LABEL), new DelegatingTokenHolder(new SimpleTokenCreator(), TokenHolder.TYPE_RELATIONSHIP_TYPE));
RecordStorageEngineRule.Builder builder = storageEngineRule.getWith(fs, pageCache, databaseLayout).tokenHolders(tokenHolders);
builder = modify(builder);
this.storageEngine = builder.build();
this.storageReader = storageEngine.newReader();
this.commitReader = storageEngine.newReader();
this.commitContext = storageEngine.newCommandCreationContext(INSTANCE);
commitContext.initialize(NULL);
storageEngineRule.before();
}
use of org.neo4j.token.DelegatingTokenHolder 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;
}
use of org.neo4j.token.DelegatingTokenHolder in project neo4j by neo4j.
the class ConsistencyCheckService method runFullConsistencyCheck.
public Result runFullConsistencyCheck(DatabaseLayout databaseLayout, Config config, ProgressMonitorFactory progressFactory, final LogProvider logProvider, final FileSystemAbstraction fileSystem, final PageCache pageCache, DebugContext debugContext, Path reportDir, ConsistencyFlags consistencyFlags, PageCacheTracer pageCacheTracer, MemoryTracker memoryTracker) throws ConsistencyCheckIncompleteException {
assertRecovered(databaseLayout, config, fileSystem, memoryTracker);
Log outLog = logProvider.getLog(getClass());
config.set(GraphDatabaseSettings.pagecache_warmup_enabled, false);
LifeSupport life = new LifeSupport();
final DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fileSystem, immediate(), databaseLayout.getDatabaseName());
DatabaseReadOnlyChecker readOnlyChecker = readOnly();
StoreFactory factory = new StoreFactory(databaseLayout, config, idGeneratorFactory, pageCache, fileSystem, logProvider, pageCacheTracer, readOnlyChecker);
// Don't start the counts stores here as part of life, instead only shut down. This is because it's better to let FullCheck
// start it and add its missing/broken detection where it can report to user.
ConsistencySummaryStatistics summary;
final Path reportFile = chooseReportPath(reportDir);
Log4jLogProvider reportLogProvider = new Log4jLogProvider(LogConfig.createBuilder(fileSystem, reportFile, Level.INFO).createOnDemand().withCategory(false).build());
Log reportLog = reportLogProvider.getLog(getClass());
Log log = new DuplicatingLog(outLog, reportLog);
// Bootstrap kernel extensions
Monitors monitors = new Monitors();
JobScheduler jobScheduler = life.add(JobSchedulerFactory.createInitialisedScheduler());
TokenHolders tokenHolders = new TokenHolders(new DelegatingTokenHolder(new ReadOnlyTokenCreator(), TokenHolder.TYPE_PROPERTY_KEY), new DelegatingTokenHolder(new ReadOnlyTokenCreator(), TokenHolder.TYPE_LABEL), new DelegatingTokenHolder(new ReadOnlyTokenCreator(), TokenHolder.TYPE_RELATIONSHIP_TYPE));
final RecoveryCleanupWorkCollector workCollector = RecoveryCleanupWorkCollector.ignore();
DatabaseExtensions extensions = life.add(instantiateExtensions(databaseLayout, fileSystem, config, new SimpleLogService(logProvider), pageCache, jobScheduler, workCollector, // We use TOOL context because it's true, and also because it uses the 'single' operational mode, which is important.
TOOL, monitors, tokenHolders, pageCacheTracer, readOnlyChecker));
DefaultIndexProviderMap indexes = life.add(new DefaultIndexProviderMap(extensions, config));
try (NeoStores neoStores = factory.openAllNeoStores()) {
long lastCommittedTransactionId = neoStores.getMetaDataStore().getLastCommittedTransactionId();
CountsStoreManager countsStoreManager = life.add(new CountsStoreManager(pageCache, fileSystem, databaseLayout, pageCacheTracer, memoryTracker, lastCommittedTransactionId));
RelationshipGroupDegreesStoreManager groupDegreesStoreManager = life.add(new RelationshipGroupDegreesStoreManager(pageCache, fileSystem, databaseLayout, pageCacheTracer, memoryTracker, lastCommittedTransactionId));
// Load tokens before starting extensions, etc.
try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(CONSISTENCY_TOKEN_READER_TAG))) {
tokenHolders.setInitialTokens(StoreTokens.allReadableTokens(neoStores), cursorContext);
}
life.start();
IndexStatisticsStore indexStatisticsStore = new IndexStatisticsStore(pageCache, databaseLayout, workCollector, readOnlyChecker, pageCacheTracer);
life.add(indexStatisticsStore);
int numberOfThreads = defaultConsistencyCheckThreadsNumber();
DirectStoreAccess stores = new DirectStoreAccess(neoStores, indexes, tokenHolders, indexStatisticsStore, idGeneratorFactory);
double memoryLimitLeewayFactor = config.get(GraphDatabaseInternalSettings.consistency_check_memory_limit_factor);
FullCheck check = new FullCheck(progressFactory, numberOfThreads, consistencyFlags, config, debugContext, NodeBasedMemoryLimiter.defaultWithLeeway(memoryLimitLeewayFactor));
summary = check.execute(pageCache, stores, countsStoreManager, groupDegreesStoreManager, null, pageCacheTracer, memoryTracker, log);
} finally {
life.shutdown();
reportLogProvider.close();
}
if (!summary.isConsistent()) {
log.warn("See '%s' for a detailed consistency report.", reportFile);
return Result.failure(reportFile, summary);
}
return Result.success(reportFile, summary);
}
use of org.neo4j.token.DelegatingTokenHolder in project neo4j by neo4j.
the class BatchingNeoStores method instantiateStores.
private void instantiateStores() throws IOException {
neoStores = newStoreFactory(databaseLayout, idGeneratorFactory, pageCacheTracer, immutable.empty()).openAllNeoStores(true);
propertyKeyRepository = new BatchingPropertyKeyTokenRepository(neoStores.getPropertyKeyTokenStore());
labelRepository = new BatchingLabelTokenRepository(neoStores.getLabelTokenStore());
relationshipTypeRepository = new BatchingRelationshipTypeTokenRepository(neoStores.getRelationshipTypeTokenStore());
tokenHolders = new TokenHolders(new DelegatingTokenHolder((key, internal) -> propertyKeyRepository.getOrCreateId(key, internal), TYPE_PROPERTY_KEY), new DelegatingTokenHolder((key, internal) -> labelRepository.getOrCreateId(key, internal), TYPE_LABEL), new DelegatingTokenHolder((key, internal) -> relationshipTypeRepository.getOrCreateId(key, internal), TYPE_RELATIONSHIP_TYPE));
tokenHolders.propertyKeyTokens().setInitialTokens(neoStores.getPropertyKeyTokenStore().getTokens(CursorContext.NULL));
temporaryNeoStores = instantiateTempStores();
try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(BATCHING_STORE_CREATION_TAG))) {
neoStores.start(cursorContext);
temporaryNeoStores.start(cursorContext);
MetaDataStore metaDataStore = neoStores.getMetaDataStore();
metaDataStore.setLastCommittedAndClosedTransactionId(initialIds.lastCommittedTransactionId(), initialIds.lastCommittedTransactionChecksum(), BASE_TX_COMMIT_TIMESTAMP, initialIds.lastCommittedTransactionLogByteOffset(), initialIds.lastCommittedTransactionLogVersion(), cursorContext);
metaDataStore.setCheckpointLogVersion(initialIds.checkpointLogVersion(), cursorContext);
}
}
use of org.neo4j.token.DelegatingTokenHolder in project neo4j by neo4j.
the class SchemaStorageReadAndWriteTest method before.
@BeforeAll
void before() throws Exception {
testDirectory.prepareDirectory(getClass(), "test");
var storeFactory = new StoreFactory(databaseLayout, Config.defaults(), new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName()), pageCache, fs, NullLogProvider.getInstance(), PageCacheTracer.NULL, writable());
neoStores = storeFactory.openNeoStores(true, StoreType.SCHEMA, StoreType.PROPERTY_KEY_TOKEN, StoreType.LABEL_TOKEN, StoreType.RELATIONSHIP_TYPE_TOKEN);
AtomicInteger tokenIdCounter = new AtomicInteger();
TokenCreator tokenCreator = (name, internal) -> tokenIdCounter.incrementAndGet();
TokenHolders tokens = new TokenHolders(new DelegatingTokenHolder(tokenCreator, TokenHolder.TYPE_PROPERTY_KEY), new DelegatingTokenHolder(tokenCreator, TokenHolder.TYPE_LABEL), new DelegatingTokenHolder(tokenCreator, TokenHolder.TYPE_RELATIONSHIP_TYPE));
tokens.setInitialTokens(StoreTokens.allTokens(neoStores), NULL);
tokenIdCounter.set(Math.max(tokenIdCounter.get(), tokens.propertyKeyTokens().size()));
tokenIdCounter.set(Math.max(tokenIdCounter.get(), tokens.labelTokens().size()));
tokenIdCounter.set(Math.max(tokenIdCounter.get(), tokens.relationshipTypeTokens().size()));
storage = new SchemaStorage(neoStores.getSchemaStore(), tokens, () -> KernelVersion.LATEST);
}
Aggregations