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

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


            // 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;
        } else {
            primaryRowKey = unstableRowLock.getPrimary();
            primaryRowLock = getRowLock(primaryRowKey.getTableName(), primaryRowKey.getRow());

            TRowKey rowKey = new TRowKey().setTableName(tableName).setRow(row);
            if (!TRowLocks.isSecondaryOf(primaryRowLock, rowKey, unstableRowLock)) {
                checkDanglingRowLockOrThrow(tableName, row, unstableRowLock);
                return null;
            }
        }
View Full Code Here


        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

        // So, we have to determine commitTimestamp properly.
        setCommitTimestamp(Math.max(getPrewriteTimestamp() + 2, maxCurrentCommitTimestamp + maxIterationCount + 2));

        extendExpiry();

        TRowKey primaryRowKey = null;
        NavigableMap<TRowKey, HaeinsaRowTransaction> mutationRowStates = txStates.getMutationRowStates();
        NavigableMap<TRowKey, HaeinsaRowTransaction> readOnlyRowStates = txStates.getReadOnlyRowStates();

        // Mutation row is preferred to be primary row than read-only row.
        if (mutationRowStates.size() > 0) {
View Full Code Here

        Preconditions.checkState(txStates.getReadOnlyRowStates().size() > 0);
        HaeinsaTablePool tablePool = getManager().getTablePool();

        // check secondaries
        for (Entry<TRowKey, HaeinsaRowTransaction> rowKeyStateEntry : txStates.getReadOnlyRowStates().entrySet()) {
            TRowKey key = rowKeyStateEntry.getKey();
            HaeinsaRowTransaction rowTx = rowKeyStateEntry.getValue();
            if (Bytes.equals(key.getTableName(), primary.getTableName())
                    && Bytes.equals(key.getRow(), primary.getRow())) {
                // if this is primaryRow
                continue;
            }
            try (HaeinsaTableIfaceInternal table = tablePool.getTableInternal(key.getTableName())) {
                table.checkSingleRowLock(rowTx, key.getRow());
            }
        }

        // check primary last
        HaeinsaTableTransaction primaryTableState = createOrGetTableState(primary.getTableName());
View Full Code Here

            table.prewrite(primaryRowState, primary.getRow(), true);
        }

        // prewrite secondaries (mutation rows)
        for (Entry<TRowKey, HaeinsaRowTransaction> rowKeyStateEntry : txStates.getMutationRowStates().entrySet()) {
            TRowKey key = rowKeyStateEntry.getKey();
            HaeinsaRowTransaction rowTx = rowKeyStateEntry.getValue();
            if (Bytes.equals(key.getTableName(), primary.getTableName())
                    && Bytes.equals(key.getRow(), primary.getRow())) {
                // if this is primaryRow
                continue;
            }
            try (HaeinsaTableIfaceInternal table = tablePool.getTableInternal(key.getTableName())) {
                table.prewrite(rowTx, key.getRow(), false);
            }
        }

        // check locking of secondaries by get (read-only rows)
        for (Entry<TRowKey, HaeinsaRowTransaction> rowKeyStateEntry : txStates.getReadOnlyRowStates().entrySet()) {
            TRowKey rowKey = rowKeyStateEntry.getKey();
            HaeinsaRowTransaction rowTx = rowKeyStateEntry.getValue();
            try (HaeinsaTableIfaceInternal table = tablePool.getTableInternal(rowKey.getTableName())) {
                table.checkSingleRowLock(rowTx, rowKey.getRow());
            }
        }

        makeStable();
    }
View Full Code Here

        }
        // if transaction reached this state, the transaction is considered as success one.
        try {
            // Change state of secondary rows to stable
            for (Entry<TRowKey, HaeinsaRowTransaction> rowKeyStateEntry : txStates.getMutationRowStates().entrySet()) {
                TRowKey rowKey = rowKeyStateEntry.getKey();
                HaeinsaRowTransaction rowTx = rowKeyStateEntry.getValue();
                try (HaeinsaTableIfaceInternal table = tablePool.getTableInternal(rowKey.getTableName())) {
                    table.applyMutations(rowTx, rowKey.getRow());
                    if (Bytes.equals(rowKey.getTableName(), primary.getTableName())
                            && Bytes.equals(rowKey.getRow(), primary.getRow())) {
                        // in case of primary row
                        continue;
                    }
                    // make secondary rows from prewritten to stable
                    table.makeStable(rowTx, rowKey.getRow());
                }
            }

            // make primary row stable
            try (HaeinsaTableIfaceInternal table = tablePool.getTableInternal(primary.getTableName())) {
View Full Code Here

            table.abortPrimary(primaryRowTx, primary.getRow());
        }

        // recover secondary mutation rows
        for (Entry<TRowKey, HaeinsaRowTransaction> rowKeyStateEntry : txStates.getMutationRowStates().entrySet()) {
            TRowKey rowKey = rowKeyStateEntry.getKey();
            HaeinsaRowTransaction rowTx = rowKeyStateEntry.getValue();
            try (HaeinsaTableIfaceInternal table = tablePool.getTableInternal(rowKey.getTableName())) {
                table.deletePrewritten(rowTx, rowKey.getRow());

                if (Bytes.equals(rowKey.getTableName(), primary.getTableName())
                        && Bytes.equals(rowKey.getRow(), primary.getRow())) {
                    continue;
                }
                // make secondary rows from prewritten to stable
                table.makeStable(rowTx, rowKey.getRow());
            }
        }

        // make primary row stable
        try (HaeinsaTableIfaceInternal table = tablePool.getTableInternal(primary.getTableName())) {
View Full Code Here

            readOnlyRowStates = Maps.newTreeMap(comparator);
            if (!onRecovery) {
                for (Entry<byte[], HaeinsaTableTransaction> tableStateEntry : tableStates.entrySet()) {
                    for (Entry<byte[], HaeinsaRowTransaction> rowStateEntry : tableStateEntry.getValue().getRowStates().entrySet()) {
                        HaeinsaRowTransaction rowState = rowStateEntry.getValue();
                        TRowKey rowKey = new TRowKey();
                        rowKey.setTableName(tableStateEntry.getKey());
                        rowKey.setRow(rowStateEntry.getKey());
                        if (rowState.getMutations().size() > 0) {
                            mutationRowStates.put(rowKey, rowState);
                        } else {
                            readOnlyRowStates.put(rowKey, rowState);
                        }
                    }
                }
            } else {
                for (Entry<byte[], HaeinsaTableTransaction> tableStateEntry : tableStates.entrySet()) {
                    for (Entry<byte[], HaeinsaRowTransaction> rowStateEntry : tableStateEntry.getValue().getRowStates().entrySet()) {
                        HaeinsaRowTransaction rowState = rowStateEntry.getValue();
                        TRowKey rowKey = new TRowKey();
                        rowKey.setTableName(tableStateEntry.getKey());
                        rowKey.setRow(rowStateEntry.getKey());
                        mutationRowStates.put(rowKey, rowState);
                    }
                }
            }
        }
View Full Code Here

        final HaeinsaTransactionManager tm = context().getTransactionManager();
        final HaeinsaTableIface testTable = context().getHaeinsaTableIface("test");
        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));
            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();
View Full Code Here

        final HaeinsaTransactionManager tm = context().getTransactionManager();
        final HaeinsaTableIface testTable = context().getHaeinsaTableIface("test");
        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());
View Full Code Here

TOP

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

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.