Search in sources :

Example 96 with Transaction

use of org.apache.tephra.Transaction in project cdap by caskdata.

the class CDAPTransactions method collect.

@Override
public void collect() throws Exception {
    Collection<MetricTimeSeries> collection = metricStore.query(new MetricDataQuery(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, METRICS, Constants.Metrics.TRANSACTION_MANAGER_CONTEXT, Collections.<String>emptyList(), null));
    for (MetricTimeSeries metricTimeSeries : collection) {
        if (metricTimeSeries.getMetricName().equals("system.committing.size")) {
            numCommittingChangeSets = (int) aggregateMetricValue(metricTimeSeries);
        }
        if (metricTimeSeries.getMetricName().equals("system.committed.size")) {
            numCommittedChangeSets = (int) aggregateMetricValue(metricTimeSeries);
        }
    }
    Transaction transaction = txClient.startShort();
    readPointer = transaction.getReadPointer();
    writePointer = transaction.getWritePointer();
    numInProgressTx = transaction.getInProgress().length;
    numInvalidTx = transaction.getInvalids().length;
    txClient.abort(transaction);
}
Also used : Transaction(org.apache.tephra.Transaction) MetricTimeSeries(co.cask.cdap.api.metrics.MetricTimeSeries) MetricDataQuery(co.cask.cdap.api.metrics.MetricDataQuery)

Example 97 with Transaction

use of org.apache.tephra.Transaction in project cdap by caskdata.

the class TransactionHttpHandlerTest method testTruncateInvalidTx.

@Test
public void testTruncateInvalidTx() throws Exception {
    TransactionSystemClient txClient = getTxClient();
    // Reset state, and assert no invalid transactions are present
    txClient.resetState();
    Assert.assertEquals(0, txClient.getInvalidSize());
    // Start few transactions and invalidate them
    Transaction tx1 = txClient.startShort();
    Transaction tx2 = txClient.startLong();
    Transaction tx3 = txClient.startLong();
    Assert.assertTrue(txClient.invalidate(tx1.getWritePointer()));
    Assert.assertTrue(txClient.invalidate(tx2.getWritePointer()));
    Assert.assertTrue(txClient.invalidate(tx3.getWritePointer()));
    Assert.assertEquals(3, txClient.getInvalidSize());
    // Remove tx1 and tx3 from invalid list
    HttpResponse response = doPost("/v3/transactions/invalid/remove/ids", GSON.toJson(ImmutableMap.of("ids", ImmutableSet.of(tx1.getWritePointer(), tx3.getWritePointer()))));
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    Assert.assertEquals(1, txClient.getInvalidSize());
}
Also used : TransactionSystemClient(org.apache.tephra.TransactionSystemClient) Transaction(org.apache.tephra.Transaction) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 98 with Transaction

use of org.apache.tephra.Transaction in project cdap by caskdata.

the class TransactionHttpHandlerTest method testTruncateInvalidTxBefore.

@Test
public void testTruncateInvalidTxBefore() throws Exception {
    TransactionSystemClient txClient = getTxClient();
    // Reset state, and assert no invalid transactions are present
    txClient.resetState();
    Assert.assertEquals(0, txClient.getInvalidSize());
    // Start few transactions and invalidate them
    Transaction tx1 = txClient.startShort();
    Transaction tx2 = txClient.startLong();
    // Sleep so that transaction ids get generated a millisecond apart for assertion
    // TEPHRA-63 should eliminate the need to sleep
    TimeUnit.MILLISECONDS.sleep(1);
    long beforeTx3 = System.currentTimeMillis();
    Transaction tx3 = txClient.startLong();
    Assert.assertTrue(txClient.invalidate(tx1.getWritePointer()));
    Assert.assertTrue(txClient.invalidate(tx2.getWritePointer()));
    Assert.assertTrue(txClient.invalidate(tx3.getWritePointer()));
    Assert.assertEquals(3, txClient.getInvalidSize());
    // Remove all transactions in invalid list beforeTx3
    HttpResponse response = doPost("/v3/transactions/invalid/remove/until", GSON.toJson(ImmutableMap.of("time", beforeTx3)));
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    Assert.assertEquals(1, txClient.getInvalidSize());
}
Also used : TransactionSystemClient(org.apache.tephra.TransactionSystemClient) Transaction(org.apache.tephra.Transaction) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 99 with Transaction

use of org.apache.tephra.Transaction in project cdap by caskdata.

the class TransactionHttpHandlerTest method testGetInvalidSize.

@Test
public void testGetInvalidSize() throws Exception {
    TransactionSystemClient txClient = getTxClient();
    // Reset state, and assert no invalid transactions are present
    txClient.resetState();
    Assert.assertEquals(0, txClient.getInvalidSize());
    // Start few transactions and invalidate them
    Transaction tx1 = txClient.startShort();
    Transaction tx2 = txClient.startLong();
    Transaction tx3 = txClient.startLong();
    Assert.assertTrue(txClient.invalidate(tx1.getWritePointer()));
    Assert.assertTrue(txClient.invalidate(tx2.getWritePointer()));
    Assert.assertTrue(txClient.invalidate(tx3.getWritePointer()));
    Assert.assertEquals(3, txClient.getInvalidSize());
    // Assert through REST API
    HttpResponse response = doGet("/v3/transactions/invalid/size");
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    Map<String, Integer> resultMap = GSON.fromJson(EntityUtils.toString(response.getEntity()), STRING_INT_TYPE);
    Assert.assertNotNull(resultMap);
    Assert.assertEquals(3, (int) resultMap.get("size"));
}
Also used : TransactionSystemClient(org.apache.tephra.TransactionSystemClient) Transaction(org.apache.tephra.Transaction) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Aggregations

Transaction (org.apache.tephra.Transaction)99 Test (org.junit.Test)54 TransactionAware (org.apache.tephra.TransactionAware)34 Table (co.cask.cdap.api.dataset.table.Table)29 DatasetAdmin (co.cask.cdap.api.dataset.DatasetAdmin)27 HBaseTable (co.cask.cdap.data2.dataset2.lib.table.hbase.HBaseTable)22 Put (co.cask.cdap.api.dataset.table.Put)12 DatasetProperties (co.cask.cdap.api.dataset.DatasetProperties)11 Get (co.cask.cdap.api.dataset.table.Get)10 TransactionSystemClient (org.apache.tephra.TransactionSystemClient)10 Row (co.cask.cdap.api.dataset.table.Row)8 ConsumerConfig (co.cask.cdap.data2.queue.ConsumerConfig)8 KeyStructValueTableDefinition (co.cask.cdap.explore.service.datasets.KeyStructValueTableDefinition)8 Scan (co.cask.cdap.api.dataset.table.Scan)7 ArrayList (java.util.ArrayList)7 CConfiguration (co.cask.cdap.common.conf.CConfiguration)6 ExploreExecutionResult (co.cask.cdap.explore.client.ExploreExecutionResult)6 DatasetId (co.cask.cdap.proto.id.DatasetId)6 IOException (java.io.IOException)6 BufferingTableTest (co.cask.cdap.data2.dataset2.lib.table.BufferingTableTest)5