Search in sources :

Example 1 with SnapshotCodecProvider

use of org.apache.tephra.snapshot.SnapshotCodecProvider in project phoenix by apache.

the class BaseTest method setupTxManager.

protected static void setupTxManager() throws SQLException, IOException {
    ConnectionInfo connInfo = ConnectionInfo.create(getUrl());
    zkClient = ZKClientServices.delegate(ZKClients.reWatchOnExpire(ZKClients.retryOnFailure(ZKClientService.Builder.of(connInfo.getZookeeperConnectionString()).setSessionTimeout(config.getInt(HConstants.ZK_SESSION_TIMEOUT, HConstants.DEFAULT_ZK_SESSION_TIMEOUT)).build(), RetryStrategies.exponentialDelay(500, 2000, TimeUnit.MILLISECONDS))));
    zkClient.startAndWait();
    DiscoveryService discovery = new ZKDiscoveryService(zkClient);
    txManager = new TransactionManager(config, new HDFSTransactionStateStorage(config, new SnapshotCodecProvider(config), new TxMetricsCollector()), new TxMetricsCollector());
    txService = new TransactionService(config, zkClient, discovery, Providers.of(txManager));
    txService.startAndWait();
}
Also used : ZKDiscoveryService(org.apache.twill.discovery.ZKDiscoveryService) HDFSTransactionStateStorage(org.apache.tephra.persist.HDFSTransactionStateStorage) TransactionService(org.apache.tephra.distributed.TransactionService) TransactionManager(org.apache.tephra.TransactionManager) TxMetricsCollector(org.apache.tephra.metrics.TxMetricsCollector) ConnectionInfo(org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo) DiscoveryService(org.apache.twill.discovery.DiscoveryService) ZKDiscoveryService(org.apache.twill.discovery.ZKDiscoveryService) SnapshotCodecProvider(org.apache.tephra.snapshot.SnapshotCodecProvider)

Example 2 with SnapshotCodecProvider

use of org.apache.tephra.snapshot.SnapshotCodecProvider in project cdap by caskdata.

the class TransactionServiceClientTest method testGetSnapshot.

@Test
public void testGetSnapshot() throws Exception {
    TransactionSystemClient client = getClient();
    SnapshotCodecProvider codecProvider = new SnapshotCodecProvider(injector.getInstance(Configuration.class));
    Transaction tx1 = client.startShort();
    long currentTime = System.currentTimeMillis();
    TransactionSnapshot snapshot;
    try (InputStream in = client.getSnapshotInputStream()) {
        snapshot = codecProvider.decode(in);
    }
    Assert.assertTrue(snapshot.getTimestamp() >= currentTime);
    Assert.assertTrue(snapshot.getInProgress().containsKey(tx1.getWritePointer()));
    // Ensures that getSnapshot didn't persist a snapshot
    TransactionSnapshot snapshotAfter = getStateStorage().getLatestSnapshot();
    if (snapshotAfter != null) {
        Assert.assertTrue(snapshot.getTimestamp() > snapshotAfter.getTimestamp());
    }
}
Also used : TransactionSystemClient(org.apache.tephra.TransactionSystemClient) TransactionSnapshot(org.apache.tephra.persist.TransactionSnapshot) CConfiguration(co.cask.cdap.common.conf.CConfiguration) Configuration(org.apache.hadoop.conf.Configuration) Transaction(org.apache.tephra.Transaction) InputStream(java.io.InputStream) SnapshotCodecProvider(org.apache.tephra.snapshot.SnapshotCodecProvider) TransactionSystemTest(org.apache.tephra.TransactionSystemTest) Test(org.junit.Test)

Example 3 with SnapshotCodecProvider

use of org.apache.tephra.snapshot.SnapshotCodecProvider in project cdap by caskdata.

the class HBaseTableCoprocessorTestRun method setupBeforeClass.

@BeforeClass
public static void setupBeforeClass() throws Exception {
    hConf = HBASE_TEST_BASE.getConfiguration();
    hConf.set(HBaseTableUtil.CFG_HBASE_TABLE_COMPRESSION, HBaseTableUtil.CompressionType.NONE.name());
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    cConf.set(Constants.CFG_HDFS_NAMESPACE, cConf.get(Constants.CFG_LOCAL_DATA_DIR));
    cConf.set(Constants.CFG_HDFS_USER, System.getProperty("user.name"));
    // Reduce the metadata cache refresh frequency for unit tests
    cConf.set(Constants.MessagingSystem.COPROCESSOR_METADATA_CACHE_UPDATE_FREQUENCY_SECONDS, Integer.toString(METADATA_CACHE_EXPIRY));
    hBaseAdmin = HBASE_TEST_BASE.getHBaseAdmin();
    hBaseAdmin.getConfiguration().set(HBaseTableUtil.CFG_HBASE_TABLE_COMPRESSION, HBaseTableUtil.CompressionType.NONE.name());
    tableUtil = new HBaseTableUtilFactory(cConf).get();
    ddlExecutor = new HBaseDDLExecutorFactory(cConf, hConf).get();
    ddlExecutor.createNamespaceIfNotExists(tableUtil.getHBaseNamespace(NamespaceId.SYSTEM));
    LocationFactory locationFactory = getInjector().getInstance(LocationFactory.class);
    tableFactory = new HBaseTableFactory(cConf, hBaseAdmin.getConfiguration(), tableUtil, locationFactory);
    ConfigurationTable configTable = new ConfigurationTable(hConf);
    configTable.write(ConfigurationTable.Type.DEFAULT, cConf);
    // write an initial transaction snapshot
    TransactionSnapshot txSnapshot = TransactionSnapshot.copyFrom(System.currentTimeMillis(), V[6] - 1, V[7], invalidSet, // this will set visibility upper bound to V[6]
    Maps.newTreeMap(ImmutableSortedMap.of(V[6], new TransactionManager.InProgressTx(V[6] - 1, Long.MAX_VALUE, TransactionManager.InProgressType.SHORT))), new HashMap<Long, Set<ChangeId>>(), new TreeMap<Long, Set<ChangeId>>());
    HDFSTransactionStateStorage tmpStorage = new HDFSTransactionStateStorage(hConf, new SnapshotCodecProvider(hConf), new TxMetricsCollector());
    tmpStorage.startAndWait();
    tmpStorage.writeSnapshot(txSnapshot);
    tmpStorage.stopAndWait();
}
Also used : Set(java.util.Set) TxMetricsCollector(org.apache.tephra.metrics.TxMetricsCollector) SnapshotCodecProvider(org.apache.tephra.snapshot.SnapshotCodecProvider) LocationFactory(org.apache.twill.filesystem.LocationFactory) HDFSTransactionStateStorage(org.apache.tephra.persist.HDFSTransactionStateStorage) TransactionSnapshot(org.apache.tephra.persist.TransactionSnapshot) ConfigurationTable(co.cask.cdap.data2.util.hbase.ConfigurationTable) TransactionManager(org.apache.tephra.TransactionManager) HBaseDDLExecutorFactory(co.cask.cdap.data2.util.hbase.HBaseDDLExecutorFactory) HBaseTableUtilFactory(co.cask.cdap.data2.util.hbase.HBaseTableUtilFactory) BeforeClass(org.junit.BeforeClass)

Aggregations

SnapshotCodecProvider (org.apache.tephra.snapshot.SnapshotCodecProvider)3 TransactionManager (org.apache.tephra.TransactionManager)2 TxMetricsCollector (org.apache.tephra.metrics.TxMetricsCollector)2 HDFSTransactionStateStorage (org.apache.tephra.persist.HDFSTransactionStateStorage)2 TransactionSnapshot (org.apache.tephra.persist.TransactionSnapshot)2 CConfiguration (co.cask.cdap.common.conf.CConfiguration)1 ConfigurationTable (co.cask.cdap.data2.util.hbase.ConfigurationTable)1 HBaseDDLExecutorFactory (co.cask.cdap.data2.util.hbase.HBaseDDLExecutorFactory)1 HBaseTableUtilFactory (co.cask.cdap.data2.util.hbase.HBaseTableUtilFactory)1 InputStream (java.io.InputStream)1 Set (java.util.Set)1 Configuration (org.apache.hadoop.conf.Configuration)1 ConnectionInfo (org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo)1 Transaction (org.apache.tephra.Transaction)1 TransactionSystemClient (org.apache.tephra.TransactionSystemClient)1 TransactionSystemTest (org.apache.tephra.TransactionSystemTest)1 TransactionService (org.apache.tephra.distributed.TransactionService)1 DiscoveryService (org.apache.twill.discovery.DiscoveryService)1 ZKDiscoveryService (org.apache.twill.discovery.ZKDiscoveryService)1 LocationFactory (org.apache.twill.filesystem.LocationFactory)1