@Override public Supplier<ManagedTimestampService> createTimestampService(String client, LeaderConfig leaderConfig) { ServiceDiscoveringAtlasSupplier atlasFactory = new ServiceDiscoveringAtlasSupplier( new MetricsManager(new MetricRegistry(), new DefaultTaggedMetricRegistry(), x -> false), kvsConfig, Optional.of(leaderConfig), Optional.empty(), Optional.of(AtlasDbConstants.TIMELOCK_TIMESTAMP_TABLE)); TimestampService timestampService = atlasFactory.getTimestampService(); Preconditions.checkArgument(TimestampManagementService.class.isInstance(timestampService), "The timestamp service is not a managed timestamp service."); return () -> new DelegatingManagedTimestampService(timestampService, (TimestampManagementService) timestampService); } }
public ServiceDiscoveringAtlasSupplier( MetricsManager metricsManager, KeyValueServiceConfig config, java.util.function.Supplier<Optional<KeyValueServiceRuntimeConfig>> runtimeConfig, Optional<LeaderConfig> leaderConfig, Optional<String> namespace, Optional<TableReference> timestampTable, boolean initializeAsync, LongSupplier timestampSupplier) { // TODO (jkong): Remove some duplication between the above constructor and this this.config = config; this.leaderConfig = leaderConfig; AtlasDbFactory atlasFactory = createAtlasFactoryOfCorrectType(config); keyValueService = Suppliers.memoize( () -> atlasFactory.createRawKeyValueService( metricsManager, config, runtimeConfig, leaderConfig, namespace, timestampSupplier, initializeAsync)); timestampService = () -> atlasFactory.createTimestampService(getKeyValueService(), timestampTable, initializeAsync); timestampStoreInvalidator = () -> atlasFactory.createTimestampStoreInvalidator(getKeyValueService()); }
@Provides @Singleton public TransactionManagers.LockAndTimestampServices provideLockAndTimestampServices( MetricsManager metricsManager, ServicesConfig config) { ServiceDiscoveringAtlasSupplier atlasSupplier = config.atlasDbSupplier(metricsManager); com.google.common.base.Supplier<TimestampService> timestampService = Suppliers.memoize(atlasSupplier::getTimestampService); com.google.common.base.Supplier<TimestampManagementService> timestampManagementService = () -> atlasSupplier.getTimestampManagementService(timestampService.get()); return TransactionManagers.createLockAndTimestampServicesForCli( metricsManager, config.atlasDbConfig(), config::atlasDbRuntimeConfig, resource -> { }, LockServiceImpl::create, timestampService, timestampManagementService, config.atlasDbSupplier(metricsManager).getTimestampStoreInvalidator(), "cli"); }
private void handleMultipleTimestampFetch() { try { String threadDumpFile = saveThreadDumps(); reportMultipleTimestampFetch(threadDumpFile); } catch (IOException e) { log.error("[timestamp-service-creation] The timestamp service was fetched for a second time. " + "We tried to output thread dumps to a temporary file, but encountered an error.", e); } }
@VisibleForTesting String saveThreadDumps() throws IOException { File file = getTempFile(); return saveThreadDumpsToFile(file); }
ServiceDiscoveringAtlasSupplier atlasFactory = new ServiceDiscoveringAtlasSupplier(metricsManager, config().keyValueService(), Suppliers.compose(AtlasDbRuntimeConfig::keyValueService, runtimeConfigSupplier::get), timestampSupplier, managementSupplier, atlasFactory.getTimestampStoreInvalidator(), userAgent()); adapter.setTimestampService(lockAndTimestampServices.timestamp()); KeyValueService kvs = atlasFactory.getKeyValueService(); kvs = ProfilingKeyValueService.create(kvs); kvs = new SafeTableClearerKeyValueService(lockAndTimestampServices.timelock()::getImmutableTimestamp, kvs);
@Test public void delegateToFactoriesAnnotatedWithAutoServiceForCreatingKeyValueServices() { ServiceDiscoveringAtlasSupplier atlasSupplier = new ServiceDiscoveringAtlasSupplier( metrics, kvsConfig, leaderConfig); assertThat( atlasSupplier.getKeyValueService(), is(delegate.createRawKeyValueService(metrics, kvsConfig, leaderConfig))); }
@Test public void alwaysSaveThreadDumpsToTheSameFile() throws IOException { ServiceDiscoveringAtlasSupplier supplier = new ServiceDiscoveringAtlasSupplier( metrics, kvsConfig, leaderConfig); String firstPath = supplier.saveThreadDumps(); String secondPath = supplier.saveThreadDumps(); assertEquals(firstPath, secondPath); }
@Value.Derived public ServiceDiscoveringAtlasSupplier atlasDbSupplier(MetricsManager metrics) { return new ServiceDiscoveringAtlasSupplier( metrics, atlasDbConfig().keyValueService(), () -> atlasDbRuntimeConfig().keyValueService(), atlasDbConfig().leader(), atlasDbConfig().namespace(), Optional.empty(), atlasDbConfig().initializeAsync(), adapter()); }
@Provides @Singleton @Named("rawKvs") public KeyValueService provideRawKeyValueService(ServicesConfig config, MetricsManager metricsManager) { return config.atlasDbSupplier(metricsManager).getKeyValueService(); }
public synchronized TimestampService getTimestampService() { log.info("[timestamp-service-creation] Fetching timestamp service from " + "thread {}. This should only happen once.", Thread.currentThread().getName()); if (timestampServiceCreationInfo == null) { timestampServiceCreationInfo = ThreadDumps.programmaticThreadDump(); } else { handleMultipleTimestampFetch(); } return timestampService.get(); }
ServiceDiscoveringAtlasSupplier atlasFactory = new ServiceDiscoveringAtlasSupplier(metricsManager, config().keyValueService(), Suppliers.compose(AtlasDbRuntimeConfig::keyValueService, runtimeConfigSupplier::get), timestampSupplier, managementSupplier, atlasFactory.getTimestampStoreInvalidator(), userAgent()); adapter.setTimestampService(lockAndTimestampServices.timestamp()); KeyValueService kvs = atlasFactory.getKeyValueService(); kvs = ProfilingKeyValueService.create(kvs); kvs = new SafeTableClearerKeyValueService(lockAndTimestampServices.timelock()::getImmutableTimestamp, kvs);
@Test public void notAllowConstructionWithoutAValidBackingFactory() { exception.expect(IllegalStateException.class); exception.expectMessage("No atlas provider"); exception.expectMessage(invalidKvsConfig.type()); exception.expectMessage("Have you annotated it with @AutoService(AtlasDbFactory.class)?"); new ServiceDiscoveringAtlasSupplier(metrics, invalidKvsConfig, leaderConfig); }
@Provides @Singleton @Named("rawKvs") public KeyValueService provideRawKeyValueService(ServicesConfig config, MetricsManager metricsManager) { return config.atlasDbSupplier(metricsManager).getKeyValueService(); }
private void handleMultipleTimestampFetch() { try { String threadDumpFile = saveThreadDumps(); reportMultipleTimestampFetch(threadDumpFile); } catch (IOException e) { log.error("[timestamp-service-creation] The timestamp service was fetched for a second time. " + "We tried to output thread dumps to a temporary file, but encountered an error.", e); } }
@VisibleForTesting String saveThreadDumps() throws IOException { File file = getTempFile(); return saveThreadDumpsToFile(file); }
public synchronized TimestampService getTimestampService() { log.info("[timestamp-service-creation] Fetching timestamp service from " + "thread {}. This should only happen once.", Thread.currentThread().getName()); if (timestampServiceCreationInfo == null) { timestampServiceCreationInfo = ThreadDumps.programmaticThreadDump(); } else { handleMultipleTimestampFetch(); } return timestampService.get(); }
@Test public void returnDifferentTimestampServicesOnSubsequentCalls() { // Need to get a newly-initialized timestamp service in case leadership changed between calls. ServiceDiscoveringAtlasSupplier supplier = new ServiceDiscoveringAtlasSupplier( metrics, kvsConfig, leaderConfig); AutoServiceAnnotatedAtlasDbFactory.nextTimestampServiceToReturn( mock(TimestampService.class), mock(TimestampService.class)); assertThat(supplier.getTimestampService(), is(not(sameObjectAs(supplier.getTimestampService())))); }
@Value.Derived public ServiceDiscoveringAtlasSupplier atlasDbSupplier(MetricsManager metrics) { return new ServiceDiscoveringAtlasSupplier( metrics, atlasDbConfig().keyValueService(), () -> atlasDbRuntimeConfig().keyValueService(), atlasDbConfig().leader(), atlasDbConfig().namespace(), Optional.empty(), atlasDbConfig().initializeAsync(), adapter()); }
public ServiceDiscoveringAtlasSupplier( MetricsManager metricsManager, KeyValueServiceConfig config, java.util.function.Supplier<Optional<KeyValueServiceRuntimeConfig>> runtimeConfig, Optional<LeaderConfig> leaderConfig, Optional<String> namespace, Optional<TableReference> timestampTable, boolean initializeAsync, LongSupplier timestampSupplier) { // TODO (jkong): Remove some duplication between the above constructor and this this.config = config; this.leaderConfig = leaderConfig; AtlasDbFactory atlasFactory = createAtlasFactoryOfCorrectType(config); keyValueService = Suppliers.memoize( () -> atlasFactory.createRawKeyValueService( metricsManager, config, runtimeConfig, leaderConfig, namespace, timestampSupplier, initializeAsync)); timestampService = () -> atlasFactory.createTimestampService(getKeyValueService(), timestampTable, initializeAsync); timestampStoreInvalidator = () -> atlasFactory.createTimestampStoreInvalidator(getKeyValueService()); }