/** * Creates a new instance of the SegmentStoreAdapter class. * * @param testConfig The Test Configuration to use. * @param builderConfig The ServiceBuilderConfig to use. * @param testExecutor An Executor to use for test-related async operations. */ SegmentStoreAdapter(TestConfig testConfig, ServiceBuilderConfig builderConfig, ScheduledExecutorService testExecutor) { this.config = Preconditions.checkNotNull(testConfig, "testConfig"); this.builderConfig = Preconditions.checkNotNull(builderConfig, "builderConfig"); this.storage = new AtomicReference<>(); this.storeExecutor = new AtomicReference<>(); this.testExecutor = Preconditions.checkNotNull(testExecutor, "testExecutor"); this.serviceBuilder = attachDataLogFactory(ServiceBuilder .newInMemoryBuilder(builderConfig) .withCacheFactory(setup -> new RocksDBCacheFactory(setup.getConfig(RocksDBConfig::builder))) .withStorageFactory(setup -> { // We use the Segment Store Executor for the real storage. SingletonStorageFactory factory = new SingletonStorageFactory(setup.getStorageExecutor()); this.storage.set(factory.createStorageAdapter()); // A bit hack-ish, but we need to get a hold of the Store Executor, so we can request snapshots for it. this.storeExecutor.set(setup.getCoreExecutor()); return factory; })); this.stopBookKeeperProcess = new Thread(this::stopBookKeeper); Runtime.getRuntime().addShutdownHook(this.stopBookKeeperProcess); }
private ServiceBuilder attachDataLogFactory(ServiceBuilder builder) { if (this.config.getBookieCount() > 0) { // We were instructed to start at least one Bookie. this.zkClient = CuratorFrameworkFactory .builder() .connectString("localhost:" + this.config.getZkPort()) .namespace("pravega") .retryPolicy(new ExponentialBackoffRetry(1000, 5)) .sessionTimeoutMs(5000) .connectionTimeoutMs(5000) .build(); this.zkClient.start(); return builder.withDataLogFactory(setup -> { BookKeeperConfig bkConfig = setup.getConfig(BookKeeperConfig::builder); return new BookKeeperLogFactory(bkConfig, this.zkClient, setup.getCoreExecutor()); }); } else { // No Bookies -> InMemory Tier1. return builder.withDataLogFactory(setup -> new InMemoryDurableDataLogFactory(setup.getCoreExecutor())); } }
private void attachDataLogFactory(ServiceBuilder builder) { builder.withDataLogFactory(setup -> { switch (this.serviceConfig.getDataLogTypeImplementation()) { case BOOKKEEPER: return new BookKeeperLogFactory(setup.getConfig(BookKeeperConfig::builder), this.zkClient, setup.getCoreExecutor()); case INMEMORY: return new InMemoryDurableDataLogFactory(setup.getCoreExecutor()); default: throw new IllegalStateException("Unsupported storage implementation: " + this.serviceConfig.getDataLogTypeImplementation()); } }); }
private void attachRocksDB(ServiceBuilder builder) { builder.withCacheFactory(setup -> new RocksDBCacheFactory(setup.getConfig(RocksDBConfig::builder))); }
@Override protected ServiceBuilder createBuilder(ServiceBuilderConfig.Builder configBuilder, int instanceId) { ServiceBuilderConfig builderConfig = getBuilderConfig(configBuilder, instanceId); return ServiceBuilder .newInMemoryBuilder(builderConfig) .withCacheFactory(setup -> new RocksDBCacheFactory(builderConfig.getConfig(RocksDBConfig::builder))) .withStorageFactory(setup -> new LocalExtendedS3StorageFactory(setup.getConfig(ExtendedS3StorageConfig::builder), setup.getStorageExecutor())) .withDataLogFactory(setup -> new BookKeeperLogFactory(setup.getConfig(BookKeeperConfig::builder), getBookkeeper().getZkClient(), setup.getCoreExecutor())); }
@Override protected ServiceBuilder createBuilder(ServiceBuilderConfig.Builder configBuilder, int instanceId) { ServiceBuilderConfig builderConfig = getBuilderConfig(configBuilder, instanceId); return ServiceBuilder .newInMemoryBuilder(builderConfig) .withCacheFactory(setup -> new RocksDBCacheFactory(builderConfig.getConfig(RocksDBConfig::builder))) .withStorageFactory(setup -> new FileSystemStorageFactory(setup.getConfig(FileSystemStorageConfig::builder), setup.getStorageExecutor())) .withDataLogFactory(setup -> new BookKeeperLogFactory(setup.getConfig(BookKeeperConfig::builder), getBookkeeper().getZkClient(), setup.getCoreExecutor())); } }
@Override protected ServiceBuilder createBuilder(ServiceBuilderConfig.Builder configBuilder, int instanceId) { ServiceBuilderConfig builderConfig = getBuilderConfig(configBuilder, instanceId); return ServiceBuilder .newInMemoryBuilder(builderConfig) .withCacheFactory(setup -> new RocksDBCacheFactory(builderConfig.getConfig(RocksDBConfig::builder))) .withStorageFactory(setup -> new HDFSStorageFactory(setup.getConfig(HDFSStorageConfig::builder), setup.getStorageExecutor())) .withDataLogFactory(setup -> new BookKeeperLogFactory(setup.getConfig(BookKeeperConfig::builder), getBookkeeper().getZkClient(), setup.getCoreExecutor())); }