@Override protected TransactionManager createManager() { MultiTableSweepQueueWriter sweepQueue = getSweepQueueWriterUninitialized(); SerializableTransactionManager txManager = SerializableTransactionManager.createForTest( MetricsManagers.createForTests(), keyValueService, timestampService, timestampManagementService, lockClient, lockService, transactionService, Suppliers.ofInstance(AtlasDbConstraintCheckingMode.FULL_CONSTRAINT_CHECKING_THROWS_EXCEPTIONS), conflictDetectionManager, SweepStrategyManagers.createDefault(keyValueService), NoOpCleaner.INSTANCE, AbstractTransactionTest.GET_RANGES_THREAD_POOL_SIZE, AbstractTransactionTest.DEFAULT_GET_RANGES_CONCURRENCY, sweepQueue); sweepQueue.initialize(txManager); return txManager; }
private enum State { INITIALIZING, READY, CLOSED, CLOSED_BY_CALLBACK_FAILURE } }
private long put(SerializableTransactionManager txm, TableReference table, String row, String val) { Cell cell = Cell.create(row.getBytes(StandardCharsets.UTF_8), COL.getBytes(StandardCharsets.UTF_8)); return txm.runTaskWithRetry(t -> { t.put(table, ImmutableMap.of(cell, val.getBytes(StandardCharsets.UTF_8))); return t.getTimestamp(); }); }
SweepStrategyManager sweepStrategyManager, Cleaner cleaner) { return new SerializableTransactionManager( metricsManager, kvs,
@Override protected int executeTimestampCommand(AtlasDbServices services) { printer.warn( "This CLI has been deprecated. Please use the timestamp/fresh-timestamp endpoint instead."); if (immutable) { timestamp = services.getTransactionManager().getImmutableTimestamp(); printer.info("The immutable timestamp is: {}", SafeArg.of("timestamp", timestamp)); } else { timestamp = services.getTimestampService().getFreshTimestamp(); printer.info("The fresh timestamp is: {}", SafeArg.of("timestamp", timestamp)); } writeTimestampToFileIfSpecified(); if (dateTime) { long timeMillis = KeyValueServicePuncherStore.getMillisForTimestamp( services.getKeyValueService(), timestamp); DateTime dt = new DateTime(timeMillis); String stringTime = ISODateTimeFormat.dateTime().print(dt); printer.info("Wall clock datetime of {} timestamp is: {}", SafeArg.of("timestamp type", immutable ? IMMUTABLE_STRING : FRESH_STRING), SafeArg.of("dateTime", stringTime)); } printer.info("Timestamp command completed succesfully."); return 0; } }
private void storeData() { services.getTransactionManager().runTaskThrowOnConflict(txn -> { Map<Cell, byte[]> values = new HashMap<>(NUM_ROWS * NUM_COLS_PER_ROW); for (int i = 0; i < NUM_ROWS; i++) { for (int j = 0; j < NUM_COLS_PER_ROW; j++) { values.put(cell(i, j), Ints.toByteArray(i * NUM_COLS_PER_ROW + j)); } } txn.put(this.tableRef, values); return null; }); }
@Override public void close() { getTransactionManager().close(); } }
@Override public long getUnreadableTimestamp() { return unreadableTs.orElse(super.getUnreadableTimestamp()); }
@Override protected SnapshotTransaction createTransaction(long immutableTimestamp, Supplier<Long> startTimestampSupplier, LockToken immutableTsLock, PreCommitCondition preCommitCondition) { return new SerializableTransaction( metricsManager, keyValueService, timelockService, transactionService, cleaner, startTimestampSupplier, getConflictDetectionManager(), sweepStrategyManager, immutableTimestamp, Optional.of(immutableTsLock), preCommitCondition, constraintModeSupplier.get(), cleaner.getTransactionReadTimeoutMillis(), TransactionReadSentinelBehavior.THROW_EXCEPTION, allowHiddenTableAccess, timestampValidationReadCache, getRangesExecutor, defaultGetRangesConcurrency, sweepQueueWriter, deleteExecutor, commitProfileProcessor, validateLocksOnReads, transactionConfig); }
TimestampManagementService timeManagement = mock(TimestampManagementService.class); LockService mockLockService = mock(LockService.class); TransactionManager txnManagerWithMocks = new SerializableTransactionManager(metricsManager, keyValueService, timelock,
@Override public int execute(AtlasDbServices services) { // test a method on each of the services if (flag1 != null) { services.getKeyValueService().getAllTableNames(); services.getTimestampService().getFreshTimestamp(); services.getLockService().getMinLockedInVersionId("test-client"); services.getTransactionManager().getImmutableTimestamp(); } // test kvs create table if (flag2 != null) { TableReference table = TableReference.createUnsafe(flag2); services.getKeyValueService().createTable(table, AtlasDbConstants.GENERIC_TABLE_METADATA); Preconditions.checkArgument(services.getKeyValueService().getAllTableNames().contains(table), "kvs contains tables %s, but not table %s", services.getKeyValueService().getAllTableNames(), table.getQualifiedName()); services.getKeyValueService().dropTable(table); } return 0; }
protected void storeData() { services.getTransactionManager().runTaskThrowOnConflict(txn -> { Map<Cell, byte[]> values = Maps.newHashMap(); allCellsAtMaxTimestamp = Maps.newHashMap(); firstCellAtMaxTimestamp = Maps.newHashMap(); firstCellAtMaxTimestamp.put(cell(0), Long.MAX_VALUE); for (int i = 0; i < getNumCols(); i++) { Cell curCell = cell(i); values.put(curCell, Ints.toByteArray(i)); allCellsAtMaxTimestamp.put(curCell, Long.MAX_VALUE); } txn.put(this.tableRef, values); return null; }); }
@Override public void close() { getTransactionManager().close(); } }
@Override public long getUnreadableTimestamp() { return unreadableTs.orElse(super.getUnreadableTimestamp()); }
@Override protected SnapshotTransaction createTransaction(long immutableTimestamp, Supplier<Long> startTimestampSupplier, LockToken immutableTsLock, PreCommitCondition preCommitCondition) { return new SerializableTransaction( metricsManager, keyValueService, timelockService, transactionService, cleaner, startTimestampSupplier, getConflictDetectionManager(), sweepStrategyManager, immutableTimestamp, Optional.of(immutableTsLock), preCommitCondition, constraintModeSupplier.get(), cleaner.getTransactionReadTimeoutMillis(), TransactionReadSentinelBehavior.THROW_EXCEPTION, allowHiddenTableAccess, timestampValidationReadCache, getRangesExecutor, defaultGetRangesConcurrency, sweepQueueWriter, deleteExecutor, commitProfileProcessor, validateLocksOnReads, transactionConfig); }
@Test public void shouldNotMakeRemoteCallsInAReadonlyTransactionIfNoWorkIsDone() { TimestampService mockTimestampService = mock(TimestampService.class); TimestampManagementService mockTimestampManagementService = mock(TimestampManagementService.class); LockService mockLockService = mock(LockService.class); TransactionManager txnManagerWithMocks = SerializableTransactionManager.createForTest( metricsManager, getKeyValueService(), mockTimestampService, mockTimestampManagementService, LockClient.of("foo"), mockLockService, transactionService, () -> AtlasDbConstraintCheckingMode.FULL_CONSTRAINT_CHECKING_THROWS_EXCEPTIONS, conflictDetectionManager, sweepStrategyManager, NoOpCleaner.INSTANCE, AbstractTransactionTest.GET_RANGES_THREAD_POOL_SIZE, AbstractTransactionTest.DEFAULT_GET_RANGES_CONCURRENCY, MultiTableSweepQueueWriter.NO_OP); // fetch an immutable timestamp once so it's cached when(mockTimestampService.getFreshTimestamp()).thenReturn(1L); when(mockLockService.getMinLockedInVersionId("foo")).thenReturn(1L); txnManagerWithMocks.getImmutableTimestamp(); verify(mockTimestampService).getFreshTimestamp(); verify(mockLockService).getMinLockedInVersionId("foo"); // now execute a read transaction txnManagerWithMocks.runTaskReadOnly(txn -> null); verifyNoMoreInteractions(mockLockService); verifyNoMoreInteractions(mockTimestampService); verifyNoMoreInteractions(mockTimestampManagementService); }
private TransactionManager getManagerWithCallback(boolean initializeAsync, Callback<TransactionManager> callBack, ScheduledExecutorService executor) { return SerializableTransactionManager.create( MetricsManagers.createForTests(), mockKvs, mockTimelockService, mockTimestampManagementService, null, // lockService null, // transactionService () -> null, // constraintMode null, // conflictDetectionManager null, // sweepStrategyManager mockCleaner, mockInitializer::isInitialized, false, // allowHiddenTableAccess TransactionTestConstants.GET_RANGES_THREAD_POOL_SIZE, TransactionTestConstants.DEFAULT_GET_RANGES_CONCURRENCY, initializeAsync, TimestampCache.createForTests(), MultiTableSweepQueueWriter.NO_OP, callBack, executor, true, () -> ImmutableTransactionConfig.builder().build()); }
services.getTransactionManager().runTaskWithRetry((TxTask) t -> { SweepPriorityTable priorityTable = SweepTableFactory.of().getSweepPriorityTable(t); SweepPriorityTable.SweepPriorityRow row1 = SweepPriorityTable.SweepPriorityRow.of(
SweepStrategyManager sweepStrategyManager, Cleaner cleaner) { return new SerializableTransactionManager( metricsManager, kvs,
@Override protected int executeTimestampCommand(AtlasDbServices services) { printer.warn( "This CLI has been deprecated. Please use the timestamp/fresh-timestamp endpoint instead."); if (immutable) { timestamp = services.getTransactionManager().getImmutableTimestamp(); printer.info("The immutable timestamp is: {}", SafeArg.of("timestamp", timestamp)); } else { timestamp = services.getTimestampService().getFreshTimestamp(); printer.info("The fresh timestamp is: {}", SafeArg.of("timestamp", timestamp)); } writeTimestampToFileIfSpecified(); if (dateTime) { long timeMillis = KeyValueServicePuncherStore.getMillisForTimestamp( services.getKeyValueService(), timestamp); DateTime dt = new DateTime(timeMillis); String stringTime = ISODateTimeFormat.dateTime().print(dt); printer.info("Wall clock datetime of {} timestamp is: {}", SafeArg.of("timestamp type", immutable ? IMMUTABLE_STRING : FRESH_STRING), SafeArg.of("dateTime", stringTime)); } printer.info("Timestamp command completed succesfully."); return 0; } }