Package com.foundationdb.directory

Examples of com.foundationdb.directory.DirectorySubspace


        OnlineSession onlineSession = getOnlineSession(session, true);
        LOG.debug("addOnlineChangeSet: {} -> {}", onlineSession.id, changeSet);
        onlineSession.tableIDs.add(changeSet.getTableId());
        TransactionState txn = txnService.getTransaction(session);
        // Require existence
        DirectorySubspace onlineDir = openDirectory (txn, smDirectory, onlineDirPath(onlineSession.id));
        // Create on demand
       DirectorySubspace changeDir = onlineDir.createOrOpen(txn.getTransaction(), CHANGES_PATH).get();
        byte[] packedKey = changeDir.pack(changeSet.getTableId());
        byte[] value = ChangeSetHelper.save(changeSet);
        txn.setBytes(packedKey, value);
        // TODO: Cleanup into Abstract. For consistency with PSSM.
        if(getAis(session).getGeneration() == getOnlineAIS(session).getGeneration()) {
            bumpGeneration(session);
View Full Code Here


        ByteBuffer buffer = null;
        validateForSession(session, newAIS, null);
        try {
            TransactionState txn = txnService.getTransaction(session);
            for(String schema : schemaNames) {
                DirectorySubspace dir = smDirectory.createOrOpen(txn.getTransaction(), PROTOBUF_PATH).get();
                buffer = storeProtobuf(txn, dir, buffer, newAIS, schema);
            }
        } catch (RuntimeException e) {
            throw FDBAdapter.wrapFDBException(session, e);
        }
View Full Code Here

        byte[] packedKey = smDirectory.pack(ONLINE_SESSION_KEY);
        byte[] value = txn.getValue(packedKey);
        long newID = (value == null) ? 1 : Tuple2.fromBytes(value).getLong(0) + 1;
        txn.setBytes(packedKey, Tuple2.from(newID).pack());
        // Create directory
        DirectorySubspace dir = createDirectory(txn, smDirectory,onlineDirPath(newID));
        packedKey = dir.pack(GENERATION_KEY);
        value = Tuple2.from(-1L).pack(); // No generation yet
        txn.setBytes(packedKey, value);
        return newID;
    }
View Full Code Here

        // Again so no other transactions see the new one from validate
        bumpGeneration(session);
        // Save online schemas
        TransactionState txn = txnService.getTransaction(session);
        List<String> idPath = onlineDirPath(onlineSession.id);
        DirectorySubspace idDir = openDirectory(txn, smDirectory, idPath);
        txn.setBytes(idDir.pack(GENERATION_KEY), Tuple2.from(newAIS.getGeneration()).pack());
       
        try {
            DirectorySubspace protobufDir = idDir.createOrOpen(txn.getTransaction(), PROTOBUF_PATH).get();
            ByteBuffer buffer = null;
            for(String name : schemas) {
                buffer = storeProtobuf(txn, protobufDir, buffer, newAIS, name);
            }
        } catch (RuntimeException e) {
View Full Code Here

        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

        Long onlineID = onlineCache.tableToOnline.get(tableID);
        if(onlineID == null) {
            throw new IllegalArgumentException("No online change for table: " + tableID);
        }
        TransactionState txn = txnService.getTransaction(session);
        DirectorySubspace tableDMLDir = getOnlineTableDMLDir(txn, onlineID, tableID);
        byte[] hKeyBytes = Arrays.copyOf(hKey.getEncodedBytes(), hKey.getEncodedSize());
        byte[] packedKey = tableDMLDir.pack(Tuple2.from(hKeyBytes));
        txn.setBytes(packedKey, new byte[0]);
    }
View Full Code Here

        Long onlineID = onlineCache.tableToOnline.get(tableID);
        if(onlineID == null) {
            throw new IllegalArgumentException("No online change for table: " + tableID);
        }
        TransactionState txn = txnService.getTransaction(session);
        DirectorySubspace onlineDir = getOnlineDir(txn, onlineID);
        byte[] packedKey = onlineDir.pack(ERROR_KEY);
        byte[] packedValue = Tuple2.from(message).pack();
        txn.setBytes(packedKey, packedValue);
    }
View Full Code Here

    @Override
    public String getOnlineDMLError(Session session) {
        OnlineSession onlineSession = getOnlineSession(session, true);
        TransactionState txn = txnService.getTransaction(session);
        DirectorySubspace dir = getOnlineDir(txn, onlineSession.id);
        byte[] value = txn.getValue(dir.pack(ERROR_KEY));
        return (value == null) ? null : Tuple2.fromBytes(value).getString(0);
    }
View Full Code Here

        OnlineSession onlineSession = getOnlineSession(session, true);
        if(LOG.isDebugEnabled()) {
            LOG.debug("addOnlineHandledHKey: {}/{} -> {}", new Object[] { onlineSession.id, tableID, hKey });
        }
        TransactionState txn = txnService.getTransaction(session);
        DirectorySubspace tableDMLDir = getOnlineTableDMLDir(txn, onlineSession.id, tableID);
        byte[] startKey = tableDMLDir.pack();
        byte[] endKey = ByteArrayUtil.strinc(startKey);
        if(hKey != null) {
            startKey = ByteArrayUtil.join(tableDMLDir.pack(), Arrays.copyOf(hKey.getEncodedBytes(), hKey.getEncodedSize()));
        }
        final Iterator<KeyValue> iterator = txn.getRangeIterator(startKey, endKey);
        final int prefixLength = tableDMLDir.pack().length;
        return new Iterator<byte[]>() {
            @Override
            public boolean hasNext() {
                throw new UnsupportedOperationException();
            }
View Full Code Here

            }
        }
    }

    private void loadPrimaryProtobuf(TransactionState txn, ProtobufReader reader, Collection<String> skipSchemas) {
        DirectorySubspace dir = smDirectory.createOrOpen(txn.getTransaction(), PROTOBUF_PATH).get();
        loadProtobufChildren(txn, dir, reader, skipSchemas);
    }
View Full Code Here

TOP

Related Classes of com.foundationdb.directory.DirectorySubspace

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.