Package kr.co.vcnc.haeinsa.thrift.generated

Examples of kr.co.vcnc.haeinsa.thrift.generated.TRowLock


     *         return null otherwise.
     * @throws IOException
     */
    @Nullable
    protected HaeinsaTransaction getTransaction(byte[] tableName, byte[] row) throws IOException {
        TRowLock unstableRowLock = getUnstableRowLock(tableName, row);

        if (unstableRowLock == null) {
            // There is no on-going transaction on the row.
            return null;
        }

        TRowLock primaryRowLock = null;
        TRowKey primaryRowKey = null;
        if (TRowLocks.isPrimary(unstableRowLock)) {
            // this row is primary row, because primary field is not set.
            primaryRowKey = new TRowKey(ByteBuffer.wrap(tableName), ByteBuffer.wrap(row));
            primaryRowLock = unstableRowLock;
View Full Code Here


     * @return null if TRowLock is {@link TRowLockState#STABLE}, otherwise
     *         return rowLock from HBase.
     * @throws IOException When error occurs in HBase.
     */
    private TRowLock getUnstableRowLock(byte[] tableName, byte[] row) throws IOException {
        TRowLock rowLock = getRowLock(tableName, row);
        if (rowLock.getState() == TRowLockState.STABLE) {
            return null;
        } else {
            return rowLock;
        }
    }
View Full Code Here

     * @param row Row key of the row
     * @return RowLock of given row from HBase
     * @throws IOException When error occurs in HBase.
     */
    private TRowLock getRowLock(byte[] tableName, byte[] row) throws IOException {
        TRowLock rowLock = null;
        try (HaeinsaTableIfaceInternal table = tablePool.getTableInternal(tableName)) {
            // access to HBase
            rowLock = table.getRowLock(row);
        }
        return rowLock;
View Full Code Here

     * @param rowLock RowLock to check if it is dangling
     * @throws IOException When error occurs. Especially throw
     *         {@link DanglingRowLockException}if given RowLock is dangling.
     */
    private void checkDanglingRowLockOrThrow(byte[] tableName, byte[] row, TRowLock rowLock) throws IOException {
        TRowLock previousRowLock = rowLock;
        TRowLock currentRowLock = getRowLock(tableName, row);

        // It is not a dangling RowLock if RowLock is changed.
        if (Objects.equal(previousRowLock, currentRowLock)) {
            if (!TRowLocks.isPrimary(currentRowLock)) {
                TRowKey primaryRowKey = currentRowLock.getPrimary();
                TRowLock primaryRowLock = getRowLock(primaryRowKey.getTableName(), primaryRowKey.getRow());

                TRowKey secondaryRowKey = new TRowKey().setTableName(tableName).setRow(row);
                if (!TRowLocks.isSecondaryOf(primaryRowLock, secondaryRowKey, currentRowLock)) {
                    throw new DanglingRowLockException(secondaryRowKey, "Primary lock doesn't have rowLock as secondary.");
                }
View Full Code Here

     * @param transaction
     * @param rowKey
     * @throws IOException
     */
    private void addSecondaryRowLock(HaeinsaTransaction transaction, TRowLock primaryRowLock, TRowKey rowKey) throws IOException {
        TRowLock secondaryRowLock = getRowLock(rowKey.getTableName(), rowKey.getRow());
        if (secondaryRowLock.getCommitTimestamp() > transaction.getCommitTimestamp()) {
            // this row isn't a part of this transaction or already aborted.
            return;
        }
        if (secondaryRowLock.getState() == TRowLockState.STABLE && secondaryRowLock.getCommitTimestamp() == transaction.getCommitTimestamp()) {
            // this row is already committed or aborted.
            return;
        }
        if (secondaryRowLock.getState() != TRowLockState.STABLE && !TRowLocks.isSecondaryOf(primaryRowLock, rowKey, secondaryRowLock)) {
            // this row isn't a part of this transaction.
            return;
        }
        HaeinsaTableTransaction tableState = transaction.createOrGetTableState(rowKey.getTableName());
        HaeinsaRowTransaction rowState = tableState.createOrGetRowState(rowKey.getRow());
View Full Code Here

            // Check whether expiry in HBase is same as expiry of HaeinsaTransaction
            Get hGet = new Get(Bytes.toBytes("brad"));
            hGet.addColumn(HaeinsaConstants.LOCK_FAMILY, HaeinsaConstants.LOCK_QUALIFIER);
            Result primaryResult = htable.get(hGet);
            TRowLock rowLock = TRowLocks.deserialize(primaryResult.getValue(HaeinsaConstants.LOCK_FAMILY, HaeinsaConstants.LOCK_QUALIFIER));
            Assert.assertEquals(rowLock.getState(), TRowLockState.PREWRITTEN);
            Assert.assertEquals(rowLock.getCommitTimestamp(), tx.getCommitTimestamp());
            Assert.assertEquals(rowLock.getExpiry(), tx.getExpiry());
        }
    }
View Full Code Here

        final HTableInterface hTestTable = context().getHTableInterface("test");

        {
            TRowKey primaryRowKey = new TRowKey().setTableName(testTable.getTableName()).setRow(Bytes.toBytes("James"));
            TRowKey danglingRowKey = new TRowKey().setTableName(testTable.getTableName()).setRow(Bytes.toBytes("Brad"));
            TRowLock danglingRowLock = new TRowLock(HaeinsaConstants.ROW_LOCK_VERSION, TRowLockState.PREWRITTEN, 1376526618707L)
                    .setCurrentTimestamp(1376526618705L)
                    .setExpiry(1376526623706L)
                    .setPrimary(primaryRowKey);

            Put hPut = new Put(danglingRowKey.getRow());
            hPut.add(HaeinsaConstants.LOCK_FAMILY, HaeinsaConstants.LOCK_QUALIFIER,
                    danglingRowLock.getCurrentTimestamp(), TRowLocks.serialize(danglingRowLock));
            hTestTable.put(hPut);

            HaeinsaTransaction tx = tm.begin();
            HaeinsaPut put = new HaeinsaPut(danglingRowKey.getRow());
            put.add(Bytes.toBytes("data"), Bytes.toBytes("balance"), Bytes.toBytes(1000));
            try {
                testTable.put(tx, put);
                tx.commit();
                Assert.fail();
            } catch (DanglingRowLockException e) {
                Assert.assertEquals(e.getDanglingRowKey(), danglingRowKey);
            }
        }

        {
            TRowKey primaryRowKey = new TRowKey().setTableName(testTable.getTableName()).setRow(Bytes.toBytes("Andrew"));
            TRowLock primaryRowLock = new TRowLock(HaeinsaConstants.ROW_LOCK_VERSION, TRowLockState.STABLE, System.currentTimeMillis());
            TRowKey danglingRowKey = new TRowKey().setTableName(testTable.getTableName()).setRow(Bytes.toBytes("Alpaca"));
            TRowLock danglingRowLock = new TRowLock(HaeinsaConstants.ROW_LOCK_VERSION, TRowLockState.PREWRITTEN, 1376526618717L)
                    .setCurrentTimestamp(1376526618715L)
                    .setExpiry(1376526623716L)
                    .setPrimary(primaryRowKey);

            Put hPut = new Put(danglingRowKey.getRow());
            hPut.add(HaeinsaConstants.LOCK_FAMILY, HaeinsaConstants.LOCK_QUALIFIER,
                    danglingRowLock.getCurrentTimestamp(), TRowLocks.serialize(danglingRowLock));
            hTestTable.put(hPut);

            hPut = new Put(primaryRowKey.getRow());
            hPut.add(HaeinsaConstants.LOCK_FAMILY, HaeinsaConstants.LOCK_QUALIFIER,
                    primaryRowLock.getCommitTimestamp(), TRowLocks.serialize(primaryRowLock));
View Full Code Here

        final HTableInterface hTestTable = context().getHTableInterface("test");

        {
            TRowKey primaryRowKey = new TRowKey().setTableName(testTable.getTableName()).setRow(Bytes.toBytes("Andrew"));
            TRowKey secondaryRowKey = new TRowKey().setTableName(testTable.getTableName()).setRow(Bytes.toBytes("Brad"));
            TRowLock secondaryRowLock = new TRowLock(HaeinsaConstants.ROW_LOCK_VERSION, TRowLockState.STABLE, 1380504156137L);
            TRowLock primaryRowLock = new TRowLock(HaeinsaConstants.ROW_LOCK_VERSION, TRowLockState.PREWRITTEN, 1380504157100L)
                                            .setCurrentTimestamp(1380504156000L)
                                            .setExpiry(1380504160000L);
            primaryRowLock.addToSecondaries(secondaryRowKey);
            Put primaryPut = new Put(primaryRowKey.getRow());
            primaryPut.add(HaeinsaConstants.LOCK_FAMILY, HaeinsaConstants.LOCK_QUALIFIER,
                    primaryRowLock.getCurrentTimestamp(), TRowLocks.serialize(primaryRowLock));
            hTestTable.put(primaryPut);

            Put secondaryPut = new Put(secondaryRowKey.getRow());
            secondaryPut.add(HaeinsaConstants.LOCK_FAMILY, HaeinsaConstants.LOCK_QUALIFIER,
                    secondaryRowLock.getCommitTimestamp(), TRowLocks.serialize(secondaryRowLock));
            hTestTable.put(secondaryPut);

            HaeinsaTransaction tx = tm.begin();
            HaeinsaGet get = new HaeinsaGet(primaryRowKey.getRow());
            HaeinsaResult result = testTable.get(tx, get);
            Assert.assertTrue(result.isEmpty());

            Get hPrimaryGet = new Get(primaryRowKey.getRow());
            hPrimaryGet.addColumn(HaeinsaConstants.LOCK_FAMILY, HaeinsaConstants.LOCK_QUALIFIER);
            Result primaryResult = hTestTable.get(hPrimaryGet);
            TRowLock stablePrimaryRowLock = TRowLocks.deserialize(primaryResult.getValue(HaeinsaConstants.LOCK_FAMILY, HaeinsaConstants.LOCK_QUALIFIER));
            Assert.assertEquals(stablePrimaryRowLock.getState(), TRowLockState.STABLE);
            Assert.assertEquals(stablePrimaryRowLock.getCommitTimestamp(), primaryRowLock.getCommitTimestamp());

            Get hSecondaryGet = new Get(secondaryRowKey.getRow());
            hSecondaryGet.addColumn(HaeinsaConstants.LOCK_FAMILY, HaeinsaConstants.LOCK_QUALIFIER);
            Result secondaryResult = hTestTable.get(hSecondaryGet);
            TRowLock stableSecondaryRowLock = TRowLocks.deserialize(secondaryResult.getValue(HaeinsaConstants.LOCK_FAMILY, HaeinsaConstants.LOCK_QUALIFIER));
            Assert.assertEquals(stableSecondaryRowLock.getState(), TRowLockState.STABLE);
            Assert.assertEquals(stableSecondaryRowLock.getCommitTimestamp(), primaryRowLock.getCommitTimestamp());
        }

        testTable.close();
        hTestTable.close();
    }
View Full Code Here

                HaeinsaKeyValue kv = scanner.peek();
                if (!Bytes.equals(kv.getRow(), row)) {
                    break;
                }

                TRowLock rowLock = scanner.peekLock();
                if (rowLock != null) {
                    return rowLock;
                }
            }
            return null;
View Full Code Here

                HaeinsaKeyValue currentKV = currentScanner.peek();
                if (prevKV == null) {
                    // start new row, deal with TRowLock and Recover()
                    if (lockInclusive) {
                        // HaeinsaKeyValues from HBaseScanScanner or HBaseGetScanner contains TRowLock for this row.
                        TRowLock currentRowLock = peekLock(currentKV.getRow());
                        HaeinsaRowTransaction rowState = tableState.createOrGetRowState(currentKV.getRow());
                        if (rowState.getCurrent() == null) {
                            // rowState is just created by createOrGetRowState method().
                            // So proper TRowLock value should be set.
                            if (currentRowLock == null) {
View Full Code Here

TOP

Related Classes of kr.co.vcnc.haeinsa.thrift.generated.TRowLock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.