Package com.foundationdb

Examples of com.foundationdb.Transaction


    @Override
    protected OnlineCache buildOnlineCache(Session session) {
        OnlineCache onlineCache = new OnlineCache();

        TransactionState txnState = txnService.getTransaction(session);
        Transaction txn = txnState.getTransaction();
       
        try {
           
            DirectorySubspace onlineDir = smDirectory.createOrOpen(txn, ONLINE_PATH).get();
   
            // For each online ID
            for(String idStr : onlineDir.list(txn).get()) {
                long onlineID = Long.parseLong(idStr);
                DirectorySubspace idDir = onlineDir.open(txn, Arrays.asList(idStr)).get();
                byte[] genBytes = txnState.getValue(idDir.pack(GENERATION_KEY));
                long generation = Tuple2.fromBytes(genBytes).getLong(0);
   
                // load protobuf
                if(idDir.exists(txn, PROTOBUF_PATH).get()) {
                    DirectorySubspace protobufDir = idDir.open(txn, PROTOBUF_PATH).get();
                    int schemaCount = 0;
                    for(String schema : protobufDir.list(txn).get()) {
                        Long prev = onlineCache.schemaToOnline.put(schema, onlineID);
                        assert (prev == null) : String.format("%s, %d, %d", schema, prev, onlineID);
                        ++schemaCount;
                    }
                    if(generation != -1) {
                        ProtobufReader reader = newProtobufReader();
                        loadProtobufChildren(txnState, protobufDir, reader, null);
                        loadPrimaryProtobuf(txnState, reader, onlineCache.schemaToOnline.keySet());
   
                        // Reader will have two copies of affected schemas, skip second (i.e. non-online)
                        AkibanInformationSchema newAIS = finishReader(reader);
                        validateAndFreeze(session, newAIS, generation);
                        buildRowDefs(session, newAIS);
                        onlineCache.onlineToAIS.put(onlineID, newAIS);
                    } else if(schemaCount != 0) {
                        throw new IllegalStateException("No generation but had schemas");
                    }
                }
   
                // Load ChangeSets
                if(idDir.exists(txn, CHANGES_PATH).get()) {
                    DirectorySubspace changesDir = idDir.open(txn, CHANGES_PATH).get();
                    for(KeyValue kv : txn.getRange(Range.startsWith(changesDir.pack()))) {
                        ChangeSet cs = ChangeSetHelper.load(kv.getValue());
                        Long prev = onlineCache.tableToOnline.put(cs.getTableId(), onlineID);
                        assert (prev == null) : String.format("%d, %d, %d", cs.getTableId(), prev, onlineID);
                        onlineCache.onlineToChangeSets.put(onlineID, cs);
                    }
View Full Code Here


    }

    @Override
    protected void renamingTable(Session session, TableName oldName, TableName newName) {
        try {
            Transaction txn = txnService.getTransaction(session).getTransaction();
            // Ensure destination schema exists. Can go away if schema lifetime becomes explicit.
            rootDir.createOrOpen(txn, PathUtil.popBack(FDBNameGenerator.dataPath(newName))).get();
            rootDir.move(txn, FDBNameGenerator.dataPath(oldName), FDBNameGenerator.dataPath(newName)).get();
        } catch (RuntimeException e) {
            throw FDBAdapter.wrapFDBException(session, e);
View Full Code Here

    }

    @Override
    public void onDrop(Session session, Table table) {
        try {
            Transaction txn = txnService.getTransaction(session).getTransaction();
            rootDir.removeIfExists(txn, FDBNameGenerator.dataPath(table.getName())).get();
        } catch (RuntimeException e) {
            throw FDBAdapter.wrapFDBException(session, e);
        }
    }
View Full Code Here

    private byte[] generate(List<String> path) {
        // Directory should always hand out unique prefixes.
        // So use createOrOpen() and do not pass to wrapped for unique check as AISValidation confirms
        try {
            Transaction txn = this.txn.getTransaction();
            DirectorySubspace indexDir = directory.createOrOpen(txn, path).get();
            return indexDir.pack();
        } catch (RuntimeException e) {
            throw FDBAdapter.wrapFDBException(this.txn.session, e);
        }
View Full Code Here

    }

    @Override
    public void finishOnlineChange(Session session, Collection<ChangeSet> changeSets) {
        TransactionState txnState = txnService.getTransaction(session);
        Transaction txn = txnState.getTransaction();
        for(ChangeSet cs : changeSets) {
            TableName oldName = new TableName(cs.getOldSchema(), cs.getOldName());
            TableName newName = new TableName(cs.getNewSchema(), cs.getNewName());

            for(Change c : cs.getIdentityChangeList()) {
View Full Code Here

        }
    }

    private void removeIfExists(Session session, DirectorySubspace dir, List<String> dirs) {
        try {
            Transaction txn = txnService.getTransaction(session).getTransaction();
            dir.removeIfExists(txn, dirs).get();
        } catch (RuntimeException e) {
            throw FDBAdapter.wrapFDBException(session, e);
        }
    }
View Full Code Here

        }

    }

    private long updateSequenceCache(Session session, Sequence s) {
        Transaction tr = txnService.getTransaction(session).getTransaction();
        byte[] prefixBytes = prefixBytes(s);
        byte[] byteValue = tr.get(prefixBytes).get();
        final long rawValue;
        if(byteValue != null) {
            Tuple2 tuple = Tuple2.fromBytes(byteValue);
            rawValue = tuple.getLong(0);
        } else {
            rawValue = 1;
        }
        tr.set(prefixBytes, Tuple2.from(rawValue + sequenceCacheSize).pack());

        Map<Object, SequenceCache> sessionMap = session.get(SEQ_UPDATES_KEY);
        if(sessionMap == null) {
            txnService.addCallback(session, TransactionService.CallbackType.COMMIT, SEQUENCE_UPDATES_PUT_CALLBACK);
            txnService.addCallback(session, TransactionService.CallbackType.END, SEQUENCE_UPDATES_CLEAR_CALLBACK);
View Full Code Here

TOP

Related Classes of com.foundationdb.Transaction

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.