public Object getFieldValue(_Fields field) { switch (field) { case TXN_HIGH_WATER_MARK: return getTxn_high_water_mark(); case OPEN_TXNS: return getOpen_txns(); case MIN_OPEN_TXN: return getMin_open_txn(); case ABORTED_BITS: return getAbortedBits(); } throw new IllegalStateException(); }
public static ValidTxnList createValidTxnListForCleaner(GetOpenTxnsResponse txns, long minOpenTxnGLB) { long highWaterMark = minOpenTxnGLB - 1; long[] abortedTxns = new long[txns.getOpen_txnsSize()]; BitSet abortedBits = BitSet.valueOf(txns.getAbortedBits()); int i = 0; for(long txnId : txns.getOpen_txns()) { if(txnId > highWaterMark) { break; } if(abortedBits.get(i)) { abortedTxns[i] = txnId; } else { assert false : JavaUtils.txnIdToString(txnId) + " is open and <= hwm:" + highWaterMark; } ++i; } abortedTxns = Arrays.copyOf(abortedTxns, i); BitSet bitSet = new BitSet(abortedTxns.length); bitSet.set(0, abortedTxns.length); //add ValidCleanerTxnList? - could be problematic for all the places that read it from // string as they'd have to know which object to instantiate return new ValidReadTxnList(abortedTxns, bitSet, highWaterMark, Long.MAX_VALUE); } /**
List<Long> openTxns = txns.getOpen_txns();
@Test public void testValidTxnsEmpty() throws Exception { GetOpenTxnsInfoResponse txnsInfo = txnHandler.getOpenTxnsInfo(); assertEquals(0L, txnsInfo.getTxn_high_water_mark()); assertTrue(txnsInfo.getOpen_txns().isEmpty()); GetOpenTxnsResponse txns = txnHandler.getOpenTxns(); assertEquals(0L, txns.getTxn_high_water_mark()); assertTrue(txns.getOpen_txns().isEmpty()); }
@Test public void testOpenTxn() throws Exception { long first = openTxn(); assertEquals(1L, first); long second = openTxn(); assertEquals(2L, second); GetOpenTxnsInfoResponse txnsInfo = txnHandler.getOpenTxnsInfo(); assertEquals(2L, txnsInfo.getTxn_high_water_mark()); assertEquals(2, txnsInfo.getOpen_txns().size()); assertEquals(1L, txnsInfo.getOpen_txns().get(0).getId()); assertEquals(TxnState.OPEN, txnsInfo.getOpen_txns().get(0).getState()); assertEquals(2L, txnsInfo.getOpen_txns().get(1).getId()); assertEquals(TxnState.OPEN, txnsInfo.getOpen_txns().get(1).getState()); assertEquals("me", txnsInfo.getOpen_txns().get(1).getUser()); assertEquals("localhost", txnsInfo.getOpen_txns().get(1).getHostname()); GetOpenTxnsResponse txns = txnHandler.getOpenTxns(); assertEquals(2L, txns.getTxn_high_water_mark()); assertEquals(2, txns.getOpen_txns().size()); boolean[] saw = new boolean[3]; for (int i = 0; i < saw.length; i++) saw[i] = false; for (Long tid : txns.getOpen_txns()) { saw[tid.intValue()] = true; } for (int i = 1; i < saw.length; i++) assertTrue(saw[i]); }
@Test public void testOpenTxn() throws Exception { long first = openTxn(); assertEquals(1L, first); long second = openTxn(); assertEquals(2L, second); GetOpenTxnsInfoResponse txnsInfo = txnHandler.getOpenTxnsInfo(); assertEquals(2L, txnsInfo.getTxn_high_water_mark()); assertEquals(2, txnsInfo.getOpen_txns().size()); assertEquals(1L, txnsInfo.getOpen_txns().get(0).getId()); assertEquals(TxnState.OPEN, txnsInfo.getOpen_txns().get(0).getState()); assertEquals(2L, txnsInfo.getOpen_txns().get(1).getId()); assertEquals(TxnState.OPEN, txnsInfo.getOpen_txns().get(1).getState()); assertEquals("me", txnsInfo.getOpen_txns().get(1).getUser()); assertEquals("localhost", txnsInfo.getOpen_txns().get(1).getHostname()); GetOpenTxnsResponse txns = txnHandler.getOpenTxns(); assertEquals(2L, txns.getTxn_high_water_mark()); assertEquals(2, txns.getOpen_txns().size()); boolean[] saw = new boolean[3]; for (int i = 0; i < saw.length; i++) saw[i] = false; for (Long tid : txns.getOpen_txns()) { saw[tid.intValue()] = true; } for (int i = 1; i < saw.length; i++) assertTrue(saw[i]); }
@Test public void testValidTxnsSomeOpen() throws Exception { txnHandler.openTxns(new OpenTxnRequest(3, "me", "localhost")); txnHandler.abortTxn(new AbortTxnRequest(1)); txnHandler.commitTxn(new CommitTxnRequest(2)); GetOpenTxnsInfoResponse txnsInfo = txnHandler.getOpenTxnsInfo(); assertEquals(3L, txnsInfo.getTxn_high_water_mark()); assertEquals(2, txnsInfo.getOpen_txns().size()); assertEquals(1L, txnsInfo.getOpen_txns().get(0).getId()); assertEquals(TxnState.ABORTED, txnsInfo.getOpen_txns().get(0).getState()); assertEquals(3L, txnsInfo.getOpen_txns().get(1).getId()); assertEquals(TxnState.OPEN, txnsInfo.getOpen_txns().get(1).getState()); GetOpenTxnsResponse txns = txnHandler.getOpenTxns(); assertEquals(3L, txns.getTxn_high_water_mark()); assertEquals(2, txns.getOpen_txns().size()); boolean[] saw = new boolean[4]; for (int i = 0; i < saw.length; i++) saw[i] = false; for (Long tid : txns.getOpen_txns()) { saw[tid.intValue()] = true; } assertTrue(saw[1]); assertFalse(saw[2]); assertTrue(saw[3]); }
@Test public void testValidTxnsNoneOpen() throws Exception { txnHandler.openTxns(new OpenTxnRequest(2, "me", "localhost")); txnHandler.commitTxn(new CommitTxnRequest(1)); txnHandler.commitTxn(new CommitTxnRequest(2)); GetOpenTxnsInfoResponse txnsInfo = txnHandler.getOpenTxnsInfo(); assertEquals(2L, txnsInfo.getTxn_high_water_mark()); assertEquals(0, txnsInfo.getOpen_txns().size()); GetOpenTxnsResponse txns = txnHandler.getOpenTxns(); assertEquals(2L, txns.getTxn_high_water_mark()); assertEquals(0, txns.getOpen_txns().size()); }
assertEquals(3, txns.getOpen_txns().size()); boolean[] saw = new boolean[4]; for (int i = 0; i < saw.length; i++) saw[i] = false; for (Long tid : txns.getOpen_txns()) { saw[tid.intValue()] = true;
public Object getFieldValue(_Fields field) { switch (field) { case TXN_HIGH_WATER_MARK: return Long.valueOf(getTxn_high_water_mark()); case OPEN_TXNS: return getOpen_txns(); } throw new IllegalStateException(); }
public Object getFieldValue(_Fields field) { switch (field) { case TXN_HIGH_WATER_MARK: return Long.valueOf(getTxn_high_water_mark()); case OPEN_TXNS: return getOpen_txns(); } throw new IllegalStateException(); }
public Object getFieldValue(_Fields field) { switch (field) { case TXN_HIGH_WATER_MARK: return getTxn_high_water_mark(); case OPEN_TXNS: return getOpen_txns(); case MIN_OPEN_TXN: return getMin_open_txn(); case ABORTED_BITS: return getAbortedBits(); } throw new IllegalStateException(); }
/** * Transform a {@link org.apache.hadoop.hive.metastore.api.GetOpenTxnsResponse} to a * {@link org.apache.hadoop.hive.common.ValidTxnList}. This assumes that the caller intends to * read the files, and thus treats both open and aborted transactions as invalid. * @param txns txn list from the metastore * @param currentTxn Current transaction that the user has open. If this is greater than 0 it * will be removed from the exceptions list so that the user sees his own * transaction as valid. * @return a valid txn list. */ public static ValidTxnList createValidReadTxnList(GetOpenTxnsResponse txns, long currentTxn) { long highWater = txns.getTxn_high_water_mark(); Set<Long> open = txns.getOpen_txns(); long[] exceptions = new long[open.size() - (currentTxn > 0 ? 1 : 0)]; int i = 0; for(long txn: open) { if (currentTxn > 0 && currentTxn == txn) continue; exceptions[i++] = txn; } return new ValidReadTxnList(exceptions, highWater); }
/** * Transform a {@link org.apache.hadoop.hive.metastore.api.GetOpenTxnsResponse} to a * {@link org.apache.hadoop.hive.common.ValidTxnList}. This assumes that the caller intends to * read the files, and thus treats both open and aborted transactions as invalid. * @param txns txn list from the metastore * @param currentTxn Current transaction that the user has open. If this is greater than 0 it * will be removed from the exceptions list so that the user sees his own * transaction as valid. * @return a valid txn list. */ public static ValidTxnList createValidReadTxnList(GetOpenTxnsResponse txns, long currentTxn) { long highWater = txns.getTxn_high_water_mark(); Set<Long> open = txns.getOpen_txns(); long[] exceptions = new long[open.size() - (currentTxn > 0 ? 1 : 0)]; int i = 0; for(long txn: open) { if (currentTxn > 0 && currentTxn == txn) continue; exceptions[i++] = txn; } return new ValidReadTxnList(exceptions, highWater); }
List<Long> openTxns = txns.getOpen_txns();