Package org.exist.storage.btree

Examples of org.exist.storage.btree.Value


        for (int q = 0; q < qnames.size(); q++) {
            for (Iterator<Collection> i = docs.getCollectionIterator(); i.hasNext();) {
                final int collectionId = i.next().getId();
                final IndexQuery query;
                if (start == null) {
                    Value startRef = new NGramQNameKey(collectionId);
                    query = new IndexQuery(IndexQuery.TRUNC_RIGHT, startRef);
                } else if (end == null) {
                    Value startRef = new NGramQNameKey(collectionId, qnames.get(q),
                        index.getBrokerPool().getSymbols(), start.toString().toLowerCase());
                    query = new IndexQuery(IndexQuery.TRUNC_RIGHT, startRef);
                } else {
                    Value startRef = new NGramQNameKey(collectionId, qnames.get(q),
                      index.getBrokerPool().getSymbols(), start.toString().toLowerCase());
                    Value endRef = new NGramQNameKey(collectionId, qnames.get(q),
                        index.getBrokerPool().getSymbols(), end.toString().toLowerCase());
                    query = new IndexQuery(IndexQuery.BW, startRef, endRef);
                }
                try {
                    lock.acquire(Lock.READ_LOCK);
View Full Code Here


            btree = new BTree(pool, (byte) 0, false, pool.getCacheManager(), file, 0.1);
            btree.create((short) -1);

            String prefixStr = "KEY";
            for (int i = 1; i <= count; i++) {
                Value value = new Value(prefixStr + Integer.toString(i));
                btree.addValue(value, i);
            }
            btree.flush();

            OutputStreamWriter writer = new OutputStreamWriter(System.out);
View Full Code Here

            btree = new BTree(pool, (byte) 0, false, pool.getCacheManager(), file, 0.1);
            btree.open((short)-1);

            String prefixStr = "KEY";
            for (int i = 1; i <= count; i++) {
                Value value = new Value(prefixStr + Integer.toString(i));
                long r = btree.findValue(value);
                if (r == -1) {
                    System.out.println("Key not found: " + i);
                }
            }
View Full Code Here

    pageNum = in.getInt();
    nextPage = in.getInt();
    final int len = in.getShort();
    final byte[] data = new byte[len];
    in.get(data);
    value = new Value(data);
  }
View Full Code Here

                boolean emptyPage = true;
                while((len = is.read(currbuf, basebuf, basemax))!=-1) {
                    emptyPage=false;
                    // We are going to use a buffer swapping technique
                    if(fullbuf != null) {
                        final Value value = new Value(fullbuf, 0, chunkSize);
                        Page nextPage = createNewPage();
                        currentPage.getPageHeader().setNextPage(nextPage.getPageNum());
                        if (isTransactional && transaction != null) {
                            final long nextPageNum = nextPage.getPageNum();
                            final Loggable loggable = new WriteOverflowPageLoggable(
                                transaction, currentPage.getPageNum(),
                                nextPageNum , value);
                            writeToLog(loggable, currentPage);
                        }
                        writeValue(currentPage, value);
                        pageCount++;
                        currentPage = nextPage;
                        fullbuf=null;
                    }
                    // Let's swap the buffer
                    basebuf += len;
                    if(basebuf == chunkSize) {
                        fullbuf = currbuf;
                        currbuf = (isaltbuf)? buf : altbuf;
                        isaltbuf = !isaltbuf;
                        basebuf = 0;
                        basemax = chunkSize;
                    } else {
                        basemax -= len;
                    }
                }
                // Detecting a zero byte stream
                if(emptyPage) {
                    currentPage.setPageNum(Page.NO_PAGE);
                    currentPage.getPageHeader().setNextPage(Page.NO_PAGE);
                } else {
                    // Just in the limit of a page
                    if (fullbuf != null) {
                        basebuf = chunkSize;
                        currbuf = fullbuf;
                    }
                    final Value value = new Value(currbuf, 0, basebuf);
                    currentPage.getPageHeader().setNextPage(Page.NO_PAGE);
                    if (isTransactional && transaction != null) {
                        final long nextPageNum = Page.NO_PAGE;
                        final Loggable loggable = new WriteOverflowPageLoggable(
                            transaction, currentPage.getPageNum(), nextPageNum , value);
View Full Code Here

                int pos = 0;
                while (remaining > 0) {
                    final int chunkSize = remaining > fileHeader.getWorkSize() ?
                        fileHeader.getWorkSize() : remaining;
                    remaining -= chunkSize;
                    final Value value = new Value(data, pos, chunkSize);
                    Page nextPage;
                    if (remaining > 0) {
                        nextPage = createNewPage();
                        currentPage.getPageHeader().setNextPage(nextPage.getPageNum());
                    } else {
View Full Code Here

        public boolean indexInfo(Value value, long pointer) {
            switch (mode) {
            case VALUES:
                final RecordPos rec = findRecord(pointer);
                final short vlen = ByteConversion.byteToShort(rec.getPage().data, rec.offset);
                values.add(new Value(rec.getPage().data, rec.offset + LENGTH_DATA_LENGTH, vlen));
                return true;
            case KEYS:
                values.add(value);
                return true;
            }
View Full Code Here

    /**
     *  Returns the raw data of the next node in document order.
     * @return the raw data of the node
     */
    public Value next() {
        Value nextValue = null;
        final Lock lock = db.getLock();
        try {
            try {
                lock.acquire(Lock.READ_LOCK);
            } catch (final LockException e) {
                LOG.error("Failed to acquire read lock on " + db.getFile().getName());
                //TODO : throw exception here ? -pb
                return null;
            }
            db.setOwnerObject(broker);
            long backLink = 0;
            do {
                final DOMFile.DOMFilePageHeader pageHeader = page.getPageHeader();
                //Next value larger than length of the current page?
                if (offset >= pageHeader.getDataLength()) {
                    //Load next page in chain
                    long nextPage = pageHeader.getNextDataPage();
                    if (nextPage == Paged.Page.NO_PAGE) {
                        SanityCheck.TRACE("Bad link to next page " + page.page.getPageInfo() +
                            "; previous: " + pageHeader.getPreviousDataPage() +
                            "; offset = " + offset + "; lastTupleID = " + lastTupleID);
                        //TODO : throw exception here ? -pb
                        return null;
                    }
                    pageNum = nextPage;
                    page = db.getDOMPage(nextPage);
                    db.addToBuffer(page);
                    offset = 0;
                }
                //Extract the tuple id
                lastTupleID = ByteConversion.byteToShort(page.data, offset);
                offset += DOMFile.LENGTH_TID;
                //Check if this is just a link to a relocated node
                if(ItemId.isLink(lastTupleID)) {
                    //Skip this
                    offset += DOMFile.LENGTH_FORWARD_LOCATION;
                    continue;
                }
                //Read data length
                short valueLength = ByteConversion.byteToShort(page.data, offset);
                offset += DOMFile.LENGTH_DATA_LENGTH;
                if (valueLength < 0) {
                    LOG.error("Got negative length" + valueLength + " at offset " + offset + "!!!");
                    LOG.debug(db.debugPageContents(page));
                    //TODO : throw an exception right now ?
                }
                if (ItemId.isRelocated(lastTupleID)) {
                    // found a relocated node. Read the original address
                    backLink = ByteConversion.byteToLong(page.data, offset);
                    offset += DOMFile.LENGTH_ORIGINAL_LOCATION;
                }
                //Overflow page? load the overflow value
                if (valueLength == DOMFile.OVERFLOW) {
                    valueLength = DOMFile.LENGTH_OVERFLOW_LOCATION;
                    final long overflow = ByteConversion.byteToLong(page.data, offset);
                    offset += DOMFile.LENGTH_OVERFLOW_LOCATION;
                    try {
                        final byte[] odata = db.getOverflowValue(overflow);
                        nextValue = new Value(odata);
                    } catch(final Exception e) {
                        LOG.error("Exception while loading overflow value: " + e.getMessage() +
                            "; originating page: " + page.page.getPageInfo());
                    }
                    // normal node
                } else {
                    try {
                        nextValue = new Value(page.data, offset, valueLength);
                        offset += valueLength;
                    } catch(final Exception e) {
                        LOG.error("Error while deserializing node: " + e.getMessage(), e);
                        LOG.error("Reading from offset: " + offset + "; len = " + valueLength);
                        LOG.debug(db.debugPageContents(page));
                        throw new RuntimeException(e);
                    }
                }
                if (nextValue == null) {
                    LOG.error("illegal node on page " + page.getPageNum() +
                        "; tupleID = " + ItemId.getId(lastTupleID) +
                        "; next = " + page.getPageHeader().getNextDataPage() +
                        "; prev = " + page.getPageHeader().getPreviousDataPage() +
                        "; offset = " + (offset - valueLength) +
                        "; len = " + page.getPageHeader().getDataLength());
                    //TODO : throw exception here ? -pb
                    return null;
                }
                if (ItemId.isRelocated(lastTupleID)) {
                    nextValue.setAddress(backLink);
                } else {
                    nextValue.setAddress(StorageAddress.createPointer((int) pageNum,
                        ItemId.getId(lastTupleID))
                    );
                }
            } while (nextValue == null);
            return nextValue;
View Full Code Here

                    + page.getPageNum() + ": expected=" + (l + 6) + "; found="
                    + data.length);
            return null;
        }
        dataCache.add(page.getFirstPage());
        final Value v = new Value(data, offset + 4, l);
        v.setAddress(p);
        return v;
    }
View Full Code Here

                long pos;
                short tid;
                DataPage page;
                int offset;
                int l;
                Value v;
                pos = StorageAddress.pageFromPointer(pointer);
                tid = StorageAddress.tidFromPointer(pointer);
                page = getDataPage(pos);
                offset = page.findValuePosition(tid);
                final byte[] data = page.getData();
                l = ByteConversion.byteToInt(data, offset);
                v = new Value(data, offset + 4, l);
                callback.info(value, v);
                return true;
            } catch (final IOException e) {
                LOG.error(e.getMessage(), e);
                return true;
View Full Code Here

TOP

Related Classes of org.exist.storage.btree.Value

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.