.withSerializer(RaftJournalSystem.createSerializer()) .withType(Type.PASSIVE) .withStorage(Storage.builder().withStorageLevel(StorageLevel.MEMORY).build()) .withStateMachine(() -> new EchoJournalStateMachine(lastUpdate)).build();
private void readLog() { Log log = Storage.builder().withDirectory(mDir).build().openLog("copycat"); for (long i = log.firstIndex(); i < log.lastIndex(); i++) { Entry entry = log.get(i); if (entry instanceof CommandEntry) { Command command = ((CommandEntry) entry).getCommand(); if (command instanceof JournalEntryCommand) { byte[] entryBytes = ((JournalEntryCommand) command).getSerializedJournalEntry(); try { System.out.println("Entry " + i + ": " + JournalEntry.parseFrom(entryBytes)); } catch (Exception e) { throw new RuntimeException(e); } } } } }
private void readSnapshot() { try (SnapshotReader snapshotReader = Storage.builder().withDirectory(mDir).build() .openSnapshotStore("copycat").currentSnapshot().reader()) { JournalEntryStreamReader reader = new JournalEntryStreamReader(new SnapshotReaderStream(snapshotReader)); while (snapshotReader.hasRemaining()) { try { System.out.println(reader.readEntry()); } catch (IOException e) { throw new RuntimeException("Failed to read snapshot", e); } } } }
ObjectHelper.ifNotEmpty(configuration.getStoragePath(), storageBuilder::withDirectory); atomixBuilder.withStorage(storageBuilder.build());
.withMajorCompactionInterval(options.majorCompactionInterval()) .withCompactionThreshold(options.compactionThreshold()) .build()) .withSerializer(options.serializer()) .withResourceTypes(options.resourceTypes())
/** * Returns a new Atomix replica builder from the given properties. * * @param properties The properties from which to load the replica builder. * @return The replica builder. */ public static Builder builder(Properties properties) { ReplicaProperties replicaProperties = new ReplicaProperties(properties); Collection<Address> replicas = replicaProperties.replicas(); return builder(replicaProperties.clientAddress(), replicaProperties.serverAddress(), replicas) .withTransport(replicaProperties.transport()) .withStorage(Storage.builder() .withStorageLevel(replicaProperties.storageLevel()) .withDirectory(replicaProperties.storageDirectory()) .withMaxSegmentSize(replicaProperties.maxSegmentSize()) .withMaxEntriesPerSegment(replicaProperties.maxEntriesPerSegment()) .withMaxSnapshotSize(replicaProperties.maxSnapshotSize()) .withRetainStaleSnapshots(replicaProperties.retainStaleSnapshots()) .withCompactionThreads(replicaProperties.compactionThreads()) .withMinorCompactionInterval(replicaProperties.minorCompactionInterval()) .withMajorCompactionInterval(replicaProperties.majorCompactionInterval()) .withCompactionThreshold(replicaProperties.compactionThreshold()) .build()) .withSerializer(replicaProperties.serializer()) .withQuorumHint(replicaProperties.quorumHint() != -1 ? replicaProperties.quorumHint() : replicas.size()) .withBackupCount(replicaProperties.backupCount()) .withElectionTimeout(replicaProperties.electionTimeout()) .withHeartbeatInterval(replicaProperties.heartbeatInterval()) .withSessionTimeout(replicaProperties.sessionTimeout()); }
atomix = builder.withStorage(storageBuilder.build()).withSessionTimeout(Duration.ofSeconds(10)) .withGlobalSuspendTimeout(Duration.ofMinutes(2)).withType(Type.ACTIVE) .withElectionTimeout(
.withMinorCompactionInterval(Duration.ofMinutes(1)) .withMajorCompactionInterval(Duration.ofMinutes(15)) .build()) .build();
/** * Creates a Copycat server. */ private CopycatServer createServer(Member member) { CopycatServer.Builder builder = CopycatServer.builder(member.clientAddress(), member.serverAddress()) .withType(member.type()) .withTransport(new NettyTransport()) .withStorage(Storage.builder() .withStorageLevel(StorageLevel.DISK) .withDirectory(new File(String.format("target/fuzz-logs/%d", member.address().hashCode()))) .withMaxSegmentSize(randomNumber(1024 * 1024 * 7) + (1024 * 1024)) .withMaxEntriesPerSegment(randomNumber(10000) + 1000) .withCompactionThreads(randomNumber(4) + 1) .withCompactionThreshold(Math.random() / (double) 2) .withEntryBufferSize(randomNumber(10000) + 1) .withFlushOnCommit(randomBoolean()) .withMinorCompactionInterval(Duration.ofSeconds(randomNumber(30) + 15)) .withMajorCompactionInterval(Duration.ofSeconds(randomNumber(60) + 60)) .build()) .withStateMachine(FuzzStateMachine::new); CopycatServer server = builder.build(); server.serializer().disableWhitelist(); servers.add(server); return server; }
/** * Sets up a server state. */ @BeforeMethod void beforeMethod() throws Throwable { serializer = new Serializer(); serializer.resolve( new ClientRequestTypeResolver(), new ClientResponseTypeResolver(), new ProtocolSerialization(), new ServerSerialization(), new StorageSerialization() ).disableWhitelist(); storageDir = Files.createTempDirectory("copycat-test"); storage = Storage.builder().withStorageLevel(StorageLevel.MEMORY).withDirectory(storageDir.toFile()).build(); members = createMembers(3); transport = new LocalTransport(new LocalServerRegistry()); serverCtx = new SingleThreadContext("test-server", serializer); new SingleThreadContext("test", serializer.clone()).executor().execute(() -> { serverContext = new ServerContext("test", members.get(0).type(), members.get(0).serverAddress(), members.get(0).clientAddress(), storage, serializer, TestStateMachine::new, new ConnectionManager(transport.client()), serverCtx); serverContext.getThreadContext().executor().execute(() -> { serverContext.getClusterState().configure(new Configuration(0, 0, Instant.now().toEpochMilli(), members)); resume(); }); }); await(1000); }
/** * Creates a Copycat server. */ private CopycatServer createServer(Member member) { CopycatServer.Builder builder = CopycatServer.builder(member.clientAddress(), member.serverAddress()) .withType(member.type()) .withTransport(new NettyTransport()) .withStorage(Storage.builder() .withStorageLevel(StorageLevel.DISK) .withDirectory(new File(String.format("target/performance-logs/%d", member.address().hashCode()))) .withCompactionThreads(1) .build()) .withStateMachine(PerformanceStateMachine::new); CopycatServer server = builder.build(); server.serializer().disableWhitelist(); servers.add(server); return server; }
/** * Creates a Copycat server. */ private CopycatServer createServer(Member member) { CopycatServer.Builder builder = CopycatServer.builder(member.clientAddress(), member.serverAddress()) .withType(member.type()) .withTransport(new LocalTransport(registry)) .withStorage(Storage.builder() .withStorageLevel(StorageLevel.MEMORY) .withMaxSegmentSize(1024 * 1024) .withCompactionThreads(1) .build()) .withStateMachine(TestStateMachine::new); CopycatServer server = builder.build(); server.serializer().disableWhitelist(); servers.add(server); return server; }
public static Storage inMemoryStorage() { return Storage.builder().withStorageLevel(StorageLevel.MEMORY).build(); } }
@Override protected Storage createStorage() { return tempStorageBuilder() .withMaxEntriesPerSegment(10) .build(); }
@Override protected Storage createStorage() { return tempStorageBuilder() .withMaxEntriesPerSegment(10) .build(); }
/** * Returns a new snapshot store. */ protected SnapshotStore createSnapshotStore() { Storage storage = Storage.builder() .withStorageLevel(StorageLevel.MEMORY) .build(); return new SnapshotStore("test", storage, new Serializer()); }
@Override protected Storage createStorage() { return tempStorageBuilder().withDirectory(new File(String.format("target/test-logs/%s", logId))) .withMaxSegmentSize(Integer.MAX_VALUE) .withMaxEntriesPerSegment(entriesPerSegment) .withStorageLevel(storageLevel()) .build(); }
/** * Returns a new metastore. */ protected MetaStore createMetaStore() { storage = Storage.builder() .withDirectory(new File(String.format("target/test-logs/%s", testId))) .build(); return new MetaStore("test", storage, new Serializer().resolve(new ProtocolSerialization(), new ServerSerialization(), new StorageSerialization()).register(TestMember.class)); }
/** * Returns a new snapshot store. */ protected SnapshotStore createSnapshotStore() { Storage storage = Storage.builder() .withStorageLevel(StorageLevel.DISK) .withDirectory(new File(String.format("target/test-logs/%s", testId))) .build(); return new SnapshotStore("test", storage, new Serializer()); }
.build(); if (mStateMachine != null) { mStateMachine.close();