@Override public boolean invalidate(long tx) { return delegate.invalidate(tx); }
@Override public boolean invalidate(long tx) { return delegate.invalidate(tx); }
@Override public boolean invalidate(long tx) { return delegate.invalidate(tx); }
@Override public boolean invalidate(long tx) { return delegate.invalidate(tx); }
@Override public boolean invalidate(long tx) { return delegate.invalidate(tx); }
@Override public boolean invalidate(long tx) { return delegate.invalidate(tx); }
@Override public boolean invalidate(final long tx) { return supplyWithRetries(() -> delegate.invalidate(tx)); } }
@Override public boolean invalidate(long tx) { try { return delegate.invalidate(tx); } catch (RuntimeException e) { throw handleException(e); } }
@Override public boolean invalidate(long tx) { try { return delegate.invalidate(tx); } catch (RuntimeException e) { throw handleException(e); } }
@Override public boolean invalidate(final long tx) { return supplyWithRetries(() -> delegate.invalidate(tx)); } }
/** * Invalidates the given transaction without throwing any exception. If there is exception raised during invalidation, * it will get logged as an error. */ public static void invalidateQuietly(TransactionSystemClient txClient, Transaction tx) { try { if (!txClient.invalidate(tx.getWritePointer())) { LOG.error("Failed to invalidate transaction {}", tx); } } catch (Throwable t) { LOG.error("Exception when invalidating transaction {}", tx, t); } }
/** * Invalidates the given transaction without throwing any exception. If there is exception raised during invalidation, * it will get logged as an error. */ public static void invalidateQuietly(TransactionSystemClient txClient, Transaction tx) { try { if (!txClient.invalidate(tx.getWritePointer())) { LOG.error("Failed to invalidate transaction {}", tx); } } catch (Throwable t) { LOG.error("Exception when invalidating transaction {}", tx, t); } }
/** * Invalidate a transaction. * @param txId transaction ID. */ @Path("/transactions/{tx-id}/invalidate") @POST public void invalidateTx(HttpRequest request, HttpResponder responder, @PathParam("tx-id") String txId) { try { long txIdLong = Long.parseLong(txId); boolean success = txClient.invalidate(txIdLong); if (success) { LOG.info("Transaction {} successfully invalidated", txId); responder.sendStatus(HttpResponseStatus.OK); } else { LOG.info("Transaction {} could not be invalidated: not in progress.", txId); responder.sendStatus(HttpResponseStatus.CONFLICT); } } catch (NumberFormatException e) { LOG.info("Could not invalidate transaction: {} is not a valid tx id", txId); responder.sendStatus(HttpResponseStatus.BAD_REQUEST); } }
/** * Invalidate a transaction. * @param txId transaction ID. */ @Path("/transactions/{tx-id}/invalidate") @POST public void invalidateTx(HttpRequest request, HttpResponder responder, @PathParam("tx-id") String txId) { try { long txIdLong = Long.parseLong(txId); boolean success = txClient.invalidate(txIdLong); if (success) { LOG.info("Transaction {} successfully invalidated", txId); responder.sendStatus(HttpResponseStatus.OK); } else { LOG.info("Transaction {} could not be invalidated: not in progress.", txId); responder.sendStatus(HttpResponseStatus.CONFLICT); } } catch (NumberFormatException e) { LOG.info("Could not invalidate transaction: {} is not a valid tx id", txId); responder.sendStatus(HttpResponseStatus.BAD_REQUEST); } }
@Override public void abortJob(JobContext jobContext, JobStatus.State state) throws IOException { try { super.abortJob(jobContext, state); } finally { try { onFinish(jobContext, false); } finally { if (transaction != null) { // invalids long running tx. All writes done by MR cannot be undone at this point. LOG.info("Invalidating transaction {}", transaction.getWritePointer()); txClient.invalidate(transaction.getWritePointer()); transaction = null; } else { LOG.warn("Did not invalidate transaction; job setup did not complete or invalidate already happened."); } } } }
@Override public void abortJob(JobContext jobContext, JobStatus.State state) throws IOException { try { super.abortJob(jobContext, state); } finally { try { onFinish(jobContext, false); } finally { if (transaction != null) { // invalids long running tx. All writes done by MR cannot be undone at this point. LOG.info("Invalidating transaction {}", transaction.getWritePointer()); txClient.invalidate(transaction.getWritePointer()); transaction = null; } else { LOG.warn("Did not invalidate transaction; job setup did not complete or invalidate already happened."); } } } }
private void closeTransaction(QueryHandle handle, OperationInfo opInfo) { try { String txCommitted = opInfo.getSessionConf().get(Constants.Explore.TX_QUERY_CLOSED); if (txCommitted != null && Boolean.parseBoolean(txCommitted)) { LOG.trace("Transaction for handle {} has already been closed", handle); return; } Transaction tx = ConfigurationUtil.get(opInfo.getSessionConf(), Constants.Explore.TX_QUERY_KEY, TxnCodec.INSTANCE); LOG.trace("Closing transaction {} for handle {}", tx, handle); if (opInfo.isReadOnly() || (opInfo.getStatus() != null && opInfo.getStatus().getStatus() == QueryStatus.OpStatus.FINISHED)) { try { txClient.commitOrThrow(tx); } catch (TransactionFailureException e) { txClient.invalidate(tx.getWritePointer()); LOG.info("Invalidating transaction: {}", tx); } } else { txClient.invalidate(tx.getWritePointer()); } } catch (Throwable e) { LOG.error("Got exception while closing transaction.", e); } finally { opInfo.getSessionConf().put(Constants.Explore.TX_QUERY_CLOSED, "true"); } }
@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.getResponseCode()); Assert.assertEquals(1, txClient.getInvalidSize()); }
@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.getResponseCode()); Assert.assertEquals(1, txClient.getInvalidSize()); }
@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.getResponseCode()); Map<String, Integer> resultMap = GSON.fromJson(response.getResponseBodyAsString(), STRING_INT_TYPE); Assert.assertNotNull(resultMap); Assert.assertEquals(3, (int) resultMap.get("size")); }