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); } } } }
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); } } } } }
Storage storage = Storage.builder() .withDirectory(mConf.getPath()) .withStorageLevel(StorageLevel.valueOf(mConf.getStorageLevel().name()))
storageBuilder.withDirectory(conf.getOrDefault(CLUSTER_ATOMIX_STORAGE_DIRECTORY, "/tmp/sidewinder-atomix"));
.withStorage(Storage.builder() .withStorageLevel(options.storageLevel()) .withDirectory(options.storageDirectory()) .withMaxSegmentSize(options.maxSegmentSize()) .withMaxEntriesPerSegment(options.maxEntriesPerSegment())
/** * 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()); }
.withTransport(new NettyTransport()) .withStorage(Storage.builder() .withDirectory(args[0]) .withMaxSegmentSize(1024 * 1024 * 32) .withMinorCompactionInterval(Duration.ofMinutes(1))
/** * 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/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; }
/** * 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; }
/** * Sets the log directory, returning the builder for method chaining. * <p> * The log will write segment files into the provided directory. If multiple {@link Storage} objects are located * on the same machine, they write logs to different directories. * * @param directory The log directory. * @return The storage builder. * @throws NullPointerException If the {@code directory} is {@code null} */ public Builder withDirectory(String directory) { return withDirectory(new File(Assert.notNull(directory, "directory"))); }
/** * Sets the log directory, returning the builder for method chaining. * <p> * The log will write segment files into the provided directory. If multiple {@link Storage} objects are located * on the same machine, they write logs to different directories. * * @param directory The log directory. * @return The storage builder. * @throws NullPointerException If the {@code directory} is {@code null} */ public Builder withDirectory(String directory) { return withDirectory(new File(Assert.notNull(directory, "directory"))); }
protected Storage.Builder tempStorageBuilder() { return Storage.builder().withDirectory(new File(String.format("target/test-logs/%s", logId))); }
/** * Sets the log directory, returning the builder for method chaining. * <p> * The log will write segment files into the provided directory. If multiple {@link Storage} objects are located * on the same machine, they write logs to different directories. * * @param directory The log directory. * @return The storage builder. * @throws NullPointerException If the {@code directory} is {@code null} */ public Builder withDirectory(String directory) { return withDirectory(new File(Assert.notNull(directory, "directory"))); }
/** * 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()); }
@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(); }