Package com.thinkaurelius.titan.diskstorage

Examples of com.thinkaurelius.titan.diskstorage.StaticBuffer


        final int addLength = additionalLength;

        BackendOperation.execute(new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                StaticBuffer oldValueCompress = store.get(key, txh);
                StaticBuffer oldValue = decompress(oldValueCompress);
                int oldLen = oldValue == null ? 0 : oldValue.length();
                int newLen = oldLen + addLength;
                Preconditions.checkArgument(newLen < MAX_BYTE_LEN, "New allocation [%s] exceeded max value length [%s] ", newLen, MAX_BYTE_LEN);
                ByteBuffer out = ByteBuffer.allocate(newLen);

                int oldindex = 0;
                int addindex = 0;
                int delindex = 0;
                while (oldindex < oldLen) {
                    int collen = fromUnsignedShort(oldValue.getShort(oldindex));
                    oldindex += COLUMN_LEN_BYTES;
                    int vallen = oldValue.getInt(oldindex);
                    oldindex += VALUE_LEN_BYTES;
                    StaticBuffer col = oldValue.subrange(oldindex, collen);
                    int cmp = -1;
                    boolean replace = false;
                    while (addindex < additions.size() && (cmp = col.compareTo(additions.get(addindex).getColumn())) >= 0) {
                        //insert before
                        insert(additions.get(addindex), out);
                        addindex++;
                        if (cmp == 0) replace = true;
                    }
                    if (delindex < deletions.size() && col.compareTo(deletions.get(delindex)) == 0) {
                        delindex++;
                    } else if (!replace) {
                        insert(col, oldValue.subrange(oldindex + collen, vallen), out);
                    }
                    //Iterate out missing deletions
                    while (delindex < deletions.size() && col.compareTo(deletions.get(delindex)) >= 0) {
                        delindex++;
                    }
                    oldindex += collen + vallen;
                }
                //Write remaining additions
                while (addindex < additions.size()) {
                    insert(additions.get(addindex), out);
                    addindex++;
                }
                out.flip();
                if (!out.hasRemaining()) {
                    store.delete(key, txh);
                } else {
                    StaticBuffer newValue = compress(new StaticByteBuffer(out));
                    store.replace(key, newValue, oldValueCompress, txh);
                }
                return null;
            }
        }, maxMutationRetries, mutationRetryWaitTimeMS);
View Full Code Here


    }

    @Override
    public long[] getIDBlock(int partition) throws StorageException {
        long blockSize = getBlockSize(partition);
        StaticBuffer partitionKey = getPartitionKey(partition);

        for (int retry = 0; retry < idApplicationRetryCount; retry++) {
            StoreTransaction txh = null;
            try {
                txh = manager.beginTransaction(new StoreTxConfig(metricsPrefix));
View Full Code Here

                // Some of this logic probably shares enough commonality with
                // CacheEntryIterator and mutate() to warrant a refactoring that
                // makes all three share common pieces of KVE-handling code
                @Override
                public boolean apply(KeyValueEntry input) {
                    StaticBuffer value = input.getValue();
                    int index = 0;
                    while (index < value.length()) {
                        int collen = fromUnsignedShort(value.getShort(index));
                        index += COLUMN_LEN_BYTES;
                        int vallen = value.getInt(index);
                        index += VALUE_LEN_BYTES;
                        StaticBuffer col = value.subrange(index, collen);
                        if (col.compareTo(slice.getSliceStart()) >= 0 && col.compareTo(slice.getSliceEnd()) < 0) {
                            return true;
                        }
                        index += collen + vallen;
                    }
                    return false;
View Full Code Here

                        }
                    }
                }
            }

            StaticBuffer vertexKey = IDHandler.getKey(vertex.getID());
            mutator.mutateEdges(vertexKey, additions, deletions);
            if (!vertex.isNew()) mutatedKeys.add(vertexKey);
            //Index Updates
            for (InternalRelation relation : edges) {
                if (relation.getVertex(0).equals(vertex)) {
View Full Code Here

            while (index < value.length()) {
                int collen = fromUnsignedShort(value.getShort(index));
                index += COLUMN_LEN_BYTES;
                int vallen = value.getInt(index);
                index += VALUE_LEN_BYTES;
                StaticBuffer col = value.subrange(index, collen);
                if (!foundStart) {
                    if (col.compareTo(slice.getSliceStart()) >= 0) {
                        foundStart = true;
                    } else {
                        index += collen + vallen;
                        continue;
                    }
                }
                if (foundStart && col.compareTo(slice.getSliceEnd()) >= 0) //the end
                    return null;

                StaticBuffer val = value.subrange(index + collen, vallen);
                index += collen + vallen;
                return new StaticBufferEntry(col, val);
            }
            return null;
        }
View Full Code Here

     * @throws Throwable                 if the storage layer throws anything else
     */
    @Override
    protected ConsistentKeyLockStatus writeSingleLock(KeyColumn lockID, StoreTransaction txh) throws Throwable {

        final StaticBuffer lockKey = serializer.toLockKey(lockID.getKey(), lockID.getColumn());
        StaticBuffer oldLockCol = null;

        for (int i = 0; i < lockRetryCount; i++) {
            WriteResult wr = tryWriteLockOnce(lockKey, oldLockCol, txh);
            if (wr.isSuccessful() && wr.getDurationNS() <= getLockWait(TimeUnit.NANOSECONDS)) {
//                log.debug("Wrote lock {} to store {} using {}", new Object[] { lockID, store.getName(), txh });
View Full Code Here

    }

    private WriteResult tryWriteLockOnce(StaticBuffer key, StaticBuffer del, StoreTransaction txh) {
        Throwable t = null;
        final long before = times.getApproxNSSinceEpoch();
        StaticBuffer newLockCol = serializer.toLockCol(before, rid);
        Entry newLockEntry = new StaticBufferEntry(newLockCol, zeroBuf);
        try {
            store.mutate(key, Arrays.asList(newLockEntry), null == del ? ImmutableList.<StaticBuffer>of() : Arrays.asList(del), overrideTimestamp(txh, before));
        } catch (StorageException e) {
            t = e;
View Full Code Here

     * @param key Key identifying the configuration property
     * @return Value stored for the key or null if the configuration property has not (yet) been defined.
     * @throws StorageException
     */
    public String getConfigurationProperty(final String key) throws StorageException {
        StaticBuffer column = string2StaticBuffer(key);
        final KeySliceQuery query = new KeySliceQuery(rowKey,column, ByteBufferUtil.nextBiggerBuffer(column),false);

        StaticBuffer result = BackendOperation.execute(new Callable<StaticBuffer>() {
            @Override
            public StaticBuffer call() throws Exception {
                StoreTransaction txh = null;
                try {
                    txh = manager.beginTransaction(new StoreTxConfig(ConsistencyLevel.KEY_CONSISTENT));
View Full Code Here

     * @param key   Key identifying the configuration property
     * @param value Value to be stored for the key
     * @throws StorageException
     */
    public void setConfigurationProperty(final String key, final String value) throws StorageException {
        StaticBuffer column = string2StaticBuffer(key);
        StaticBuffer val = string2StaticBuffer(value);
        final List<Entry> additions = new ArrayList<Entry>(1);
        additions.add(new StaticBufferEntry(column,val));

        BackendOperation.execute(new Callable<Boolean>() {
            @Override
View Full Code Here

        for (long tid : remaining) {
            TitanType t = tx.getExistingType(tid);
            writeInline(writer, t, relation.getProperty(t), true);
        }

        StaticBuffer column = ((InternalType)type).getSortOrder()==Order.DESC?
                                    colOut.getStaticBufferFlipBytes(startPosition,endPosition):
                                    colOut.getStaticBuffer();
        return new StaticBufferEntry(column, writer.getStaticBuffer());
    }
View Full Code Here

TOP

Related Classes of com.thinkaurelius.titan.diskstorage.StaticBuffer

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.