com.palantir.atlasdb.transaction.api.TransactionManager类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(121)

本文整理了Java中com.palantir.atlasdb.transaction.api.TransactionManager类的一些代码示例,展示了TransactionManager类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TransactionManager类的具体详情如下:
包路径:com.palantir.atlasdb.transaction.api.TransactionManager
类名称:TransactionManager

TransactionManager介绍

暂无

代码示例

代码示例来源:origin: palantir/atlasdb

public static TransactionManager mockTxManager() {
  TransactionManager txManager = mock(TransactionManager.class);
  Answer runTaskAnswer = inv -> {
    Object[] args = inv.getArguments();
    TransactionTask<?, ?> task = (TransactionTask<?, ?>) args[0];
    return task.execute(mock(Transaction.class));
  };
  doAnswer(runTaskAnswer).when(txManager).runTaskReadOnly(any());
  doAnswer(runTaskAnswer).when(txManager).runTaskWithRetry(any());
  return txManager;
}

代码示例来源:origin: palantir/atlasdb

@Test
public void shouldNotRunTaskWithRetryWithClosedTransactionManager() {
  txMgr.close();
  assertThatThrownBy(() -> txMgr.runTaskWithRetry((TransactionTask<Void, RuntimeException>) txn -> {
    put(txn, "row1", "col1", "v1");
    return null;
  }))
      .isInstanceOf(IllegalStateException.class)
      .hasMessage("Operations cannot be performed on closed TransactionManager.");
}

代码示例来源:origin: palantir/atlasdb

protected final void storeMetadataAndIndex(final long streamId, final StreamMetadata metadata) {
  Preconditions.checkNotNull(txnMgr, "Transaction manager must not be null");
  txnMgr.runTaskThrowOnConflict((TxTask) tx -> {
    putMetadataAndHashIndexTask(tx, streamId, metadata);
    return null;
  });
}

代码示例来源:origin: palantir/atlasdb

public void initializeWithoutRunning(TransactionManager txManager) {
  initializeWithoutRunning(SpecialTimestampsSupplier.create(txManager),
      txManager.getTimelockService(),
      txManager.getKeyValueService(),
      TransactionServices.createTransactionService(txManager.getKeyValueService(),
          CoordinationServices.createDefault(
              txManager.getKeyValueService(),
              txManager.getTimestampService(),
              false)),
      new TargetedSweepFollower(followers, txManager));
}

代码示例来源:origin: palantir/atlasdb

private boolean isInitializedInternal() {
  // Note that the PersistentLockService is also initialized asynchronously as part of
  // TransactionManagers.create; however, this is not required for the TransactionManager to fulfil
  // requests (note that it is not accessible from any TransactionManager implementation), so we omit
  // checking here whether it is initialized.
  return txManager.getKeyValueService().isInitialized()
      && txManager.getTimelockService().isInitialized()
      && txManager.getTimestampService().isInitialized()
      && txManager.getCleaner().isInitialized()
      && initializationPrerequisite.get();
}

代码示例来源:origin: palantir/atlasdb

@Override
public boolean doTransactionAndReportOutcome() {
  try {
    return transactionManager.runTaskThrowOnConflict(tx -> {
      KeyValueService kvs = transactionManager.getKeyValueService();
      kvs.createTable(TEST_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA);
      tx.put(TEST_TABLE, ImmutableMap.of(TEST_CELL, new byte[1]));
      return true;
    });
  } catch (Exception e) {
    return false;
  }
}

代码示例来源:origin: palantir/atlasdb

private void validateTable(final TableReference table, final int limit, final Transaction t1) {
  // read only, but need to use a write tx in case the source table has SweepStrategy.THOROUGH
  validationToTransactionManager.runTaskWithRetry(
      (TransactionTask<Map<Cell, byte[]>, RuntimeException>) t2 -> {
        validateTable(table, limit, t1, t2);
        return null;
      });
}

代码示例来源:origin: palantir/atlasdb

Optional<String> selectTableToCompact() {
  return transactionManager.runTaskReadOnly(this::selectTableToCompactInternal);
}

代码示例来源:origin: palantir/atlasdb

@Override
public void init(TransactionManager resource) {
  try {
    resource.getKeyValueService().dropTables(deprecatedTables);
    log.info("Successfully dropped deprecated tables on startup.");
  } catch (Throwable e) {
    log.info("Could not drop deprecated tables from the underlying KeyValueService.", e);
  }
}

代码示例来源:origin: palantir/atlasdb

@After
public void closeTransactionManager() {
  txManager.close();
}

代码示例来源:origin: palantir/atlasdb

@Test
public void shouldNotRunTaskReadOnlyWithClosedTransactionManager() {
  txMgr.close();
  assertThatThrownBy(() -> txMgr.runTaskReadOnly((TransactionTask<Void, RuntimeException>) txn -> {
    put(txn, "row1", "col1", "v1");
    return null;
  }))
      .isInstanceOf(IllegalStateException.class)
      .hasMessage("Operations cannot be performed on closed TransactionManager.");
}

代码示例来源:origin: palantir/atlasdb

public static CoordinationResource create(TransactionManager transactionManager) {
  return new SimpleCoordinationResource(transactionManager,
      new TransactionSchemaManager(
          CoordinationServices.createDefault(
          transactionManager.getKeyValueService(),
          transactionManager.getTimestampService(),
          false)));
}

代码示例来源:origin: palantir/atlasdb

@Test
public void shouldNotRunTaskThrowOnConflictWithClosedTransactionManager() {
  txMgr.close();
  assertThatThrownBy(() -> txMgr.runTaskThrowOnConflict((TransactionTask<Void, RuntimeException>) txn -> {
    put(txn, "row1", "col1", "v1");
    return null;
  }))
      .isInstanceOf(IllegalStateException.class)
      .hasMessage("Operations cannot be performed on closed TransactionManager.");
}

代码示例来源:origin: palantir/atlasdb

@Override
public void registerClosingCallback(Runnable closingCallback) {
  assertOpen();
  txManager.registerClosingCallback(closingCallback);
}

代码示例来源:origin: palantir/atlasdb

@Test
public void runsClosingCallbackOnShutdown() throws Exception {
  AtlasDbConfig atlasDbConfig = ImmutableAtlasDbConfig.builder()
      .keyValueService(new InMemoryAtlasDbConfig())
      .defaultLockTimeoutSeconds(120)
      .build();
  Runnable callback = mock(Runnable.class);
  TransactionManager manager = TransactionManagers.builder()
      .config(atlasDbConfig)
      .userAgent("test")
      .globalMetricsRegistry(new MetricRegistry())
      .globalTaggedMetricRegistry(DefaultTaggedMetricRegistry.getDefault())
      .registrar(environment)
      .build()
      .serializable();
  manager.registerClosingCallback(callback);
  manager.close();
  verify(callback, times(1)).run();
}

代码示例来源:origin: palantir/atlasdb

private SimpleCoordinationResource(
    TransactionManager transactionManager,
    TransactionSchemaManager transactionSchemaManager) {
  this.transactionManager = transactionManager;
  this.transactionSchemaManager = transactionSchemaManager;
  this.timestampService = transactionManager.getTimestampService();
}

代码示例来源:origin: palantir/atlasdb

@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);
}

代码示例来源:origin: palantir/atlasdb

@Override
public LockService getLockService() {
  assertOpen();
  return txManager.getLockService();
}

代码示例来源:origin: palantir/atlasdb

@Override
public final void performOneCall() {
  txnManager.runTaskWithRetry(txn -> {
    writeValues(txn, allValues);
    return null;
  });
}

代码示例来源:origin: palantir/atlasdb

private TargetedSweeper initializeAndGet(TargetedSweeper sweeper, TransactionManager txManager) {
  sweeper.initializeWithoutRunning(
      new SpecialTimestampsSupplier(txManager::getImmutableTimestamp, txManager::getImmutableTimestamp),
      txManager.getTimelockService(),
      txManager.getKeyValueService(),
      TransactionServices.createForTesting(
          txManager.getKeyValueService(), txManager.getTimestampService(), false),
      new TargetedSweepFollower(ImmutableList.of(FOLLOWER), txManager));
  sweeper.runInBackground();
  return sweeper;
}

相关文章