use of org.neo4j.causalclustering.core.replication.session.GlobalSessionTrackerState in project neo4j by neo4j.
the class CoreBootstrapperTest method shouldSetAllCoreState.
@Test
public void shouldSetAllCoreState() throws Exception {
// given
int nodeCount = 100;
FileSystemAbstraction fileSystem = fileSystemRule.get();
File classicNeo4jStore = RestoreClusterUtils.createClassicNeo4jStore(testDirectory.directory(), fileSystem, nodeCount, Standard.LATEST_NAME);
PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
CoreBootstrapper bootstrapper = new CoreBootstrapper(classicNeo4jStore, pageCache, fileSystem, Config.defaults(), NullLogProvider.getInstance());
// when
Set<MemberId> membership = asSet(randomMember(), randomMember(), randomMember());
CoreSnapshot snapshot = bootstrapper.bootstrap(membership);
// then
assertEquals(nodeCount, ((IdAllocationState) snapshot.get(CoreStateType.ID_ALLOCATION)).firstUnallocated(IdType.NODE));
/* Bootstrapped state is created in RAFT land at index -1 and term -1. */
assertEquals(0, snapshot.prevIndex());
assertEquals(0, snapshot.prevTerm());
/* Lock is initially not taken. */
assertEquals(new ReplicatedLockTokenState(), snapshot.get(CoreStateType.LOCK_TOKEN));
/* Raft has the bootstrapped set of members initially. */
assertEquals(membership, ((RaftCoreState) snapshot.get(CoreStateType.RAFT_CORE_STATE)).committed().members());
/* The session state is initially empty. */
assertEquals(new GlobalSessionTrackerState(), snapshot.get(CoreStateType.SESSION_TRACKER));
LastCommittedIndexFinder lastCommittedIndexFinder = new LastCommittedIndexFinder(new ReadOnlyTransactionIdStore(pageCache, classicNeo4jStore), new ReadOnlyTransactionStore(pageCache, fileSystem, classicNeo4jStore, new Monitors()), NullLogProvider.getInstance());
long lastCommittedIndex = lastCommittedIndexFinder.getLastCommittedIndex();
assertEquals(-1, lastCommittedIndex);
}
use of org.neo4j.causalclustering.core.replication.session.GlobalSessionTrackerState in project neo4j by neo4j.
the class CoreBootstrapper method bootstrap.
public CoreSnapshot bootstrap(Set<MemberId> members) throws IOException {
StoreFactory factory = new StoreFactory(storeDir, config, new DefaultIdGeneratorFactory(fs), pageCache, fs, logProvider);
NeoStores neoStores = factory.openAllNeoStores(true);
neoStores.close();
CoreSnapshot coreSnapshot = new CoreSnapshot(FIRST_INDEX, FIRST_TERM);
coreSnapshot.add(CoreStateType.ID_ALLOCATION, deriveIdAllocationState(storeDir));
coreSnapshot.add(CoreStateType.LOCK_TOKEN, new ReplicatedLockTokenState());
coreSnapshot.add(CoreStateType.RAFT_CORE_STATE, new RaftCoreState(new MembershipEntry(FIRST_INDEX, members)));
coreSnapshot.add(CoreStateType.SESSION_TRACKER, new GlobalSessionTrackerState());
appendNullTransactionLogEntryToSetRaftIndexToMinusOne();
return coreSnapshot;
}
Aggregations