Package org.apache.jackrabbit.oak.plugins.segment

Examples of org.apache.jackrabbit.oak.plugins.segment.Segment


        return id.getTracker() == tracker || segments.containsKey(id);
    }

    @Override @Nonnull
    public Segment readSegment(SegmentId id) {
        Segment segment = segments.get(id);
        if (segment != null) {
            return segment;
        }
        throw new SegmentNotFoundException(id);
    }
View Full Code Here


    public void writeSegment(
            SegmentId id, byte[] data, int offset, int length) {
        ByteBuffer buffer = ByteBuffer.allocate(length);
        buffer.put(data, offset, length);
        buffer.rewind();
        Segment segment = new Segment(tracker, id, buffer);
        if (segments.putIfAbsent(id, segment) != null) {
            throw new IllegalStateException("Segment override: " + id);
        }
    }
View Full Code Here

            } else if (request.startsWith(Messages.GET_SEGMENT)) {
                String sid = request.substring(Messages.GET_SEGMENT.length());
                log.debug("request segment id {}", sid);
                UUID uuid = UUID.fromString(sid);

                Segment s = null;

                for (int i = 0; i < 10; i++) {
                    try {
                        s = store.readSegment(new SegmentId(store.getTracker(),
                                uuid.getMostSignificantBits(), uuid
                                .getLeastSignificantBits()));
                    } catch (IllegalStateException e) {
                        // segment not found
                        log.debug("waiting for segment. Got exception: " + e.getMessage());
                        TimeUnit.MILLISECONDS.sleep(1000);
                    }
                    if (s != null) break;
                }

                if (s != null) {
                    log.debug("sending segment " + sid + " to " + client);
                    ctx.writeAndFlush(s);
                    observer.didSendSegmentBytes(clientID, s.size());
                    return;
                }
            } else {
                log.warn("Unknown request {}, ignoring.", request);
            }
View Full Code Here

        try {
            URLConnection connection = get(id.toString());
            InputStream stream = connection.getInputStream();
            try {
                byte[] data = ByteStreams.toByteArray(stream);
                return new Segment(tracker, id, ByteBuffer.wrap(data));
            } finally {
                stream.close();
            }
        } catch (MalformedURLException e) {
            throw new SegmentNotFoundException(id, e);
View Full Code Here

        frame.getBytes(29, segment);
        Hasher hasher = Hashing.murmur3_32().newHasher();
        long check = hasher.putBytes(segment).hash().padToLong();
        if (hash == check) {
            SegmentId id = new SegmentId(store.getTracker(), msb, lsb);
            Segment s = new Segment(store.getTracker(), id,
                    ByteBuffer.wrap(segment));
            log.debug("received type {} with id {} and size {}", type, id,
                    s.size());
            return s;
        }
        log.debug("received corrupted segment {}, ignoring", new UUID(msb, lsb));
        return null;
View Full Code Here

                }
                catch (SegmentNotFoundException e) {
                    // the segment is locally damaged or not present anymore
                    // lets try to read this from the primary again
                    String id = e.getSegmentId();
                    Segment s = readSegment(e.getSegmentId());
                    if (s == null) {
                        log.warn("can't read locally corrupt segment " + id + " from primary");
                        throw e;
                    }

                    log.debug("did reread locally corrupt segment " + id + " with size " + s.size());
                    ByteArrayOutputStream bout = new ByteArrayOutputStream(s.size());
                    try {
                        s.writeTo(bout);
                    }
                    catch (IOException f) {
                        log.error("can't wrap segment to output stream", f);
                        throw e;
                    }
                    store.writeSegment(s.getSegmentId(), bout.toByteArray(), 0, s.size());
                }
            } while(true);
            boolean ok = store.setHead(before, builder.getNodeState());
            log.debug("updated head state successfully: {} in {}ms.", ok,
                    System.currentTimeMillis() - t);
View Full Code Here

        boolean interrupted = false;
        try {
            for (;;) {
                try {
                    // log.debug("polling segment");
                    Segment s = segment.poll(timeoutMs, TimeUnit.MILLISECONDS);
                    // log.debug("returning segment " + s.getSegmentId());
                    return s;
                } catch (InterruptedException ignore) {
                    interrupted = true;
                }
View Full Code Here

        while (!ids.isEmpty()) {
            SegmentId id = ids.remove();
            if (!seen.contains(id) && !delegate.containsSegment(id)) {
                log.debug("trying to read segment " + id);
                Segment s = loader.readSegment(id.toString());
                if (s != null) {
                    log.debug("got segment " + id + " with size " + s.size());
                    ByteArrayOutputStream bout = new ByteArrayOutputStream(
                            s.size());
                    if (id.isDataSegmentId()) {
                        ids.addAll(s.getReferencedIds());
                    }
                    try {
                        s.writeTo(bout);
                        writeSegment(id, bout.toByteArray(), 0, s.size());
                    } catch (IOException e) {
                        throw new IllegalStateException(
                                "Unable to write remote segment " + id, e);
                    }
                    seen.add(id);
View Full Code Here

        return id.getTracker() == tracker || segments.containsKey(id);
    }

    @Override @Nonnull
    public Segment readSegment(SegmentId id) {
        Segment segment = segments.get(id);
        if (segment != null) {
            return segment;
        } else {
            throw new IllegalArgumentException("Segment not found: " + id);
        }
View Full Code Here

    public void writeSegment(
            SegmentId id, byte[] data, int offset, int length) {
        ByteBuffer buffer = ByteBuffer.allocate(length);
        buffer.put(data, offset, length);
        buffer.rewind();
        Segment segment = new Segment(tracker, id, buffer);
        if (segments.putIfAbsent(id, segment) != null) {
            throw new IllegalStateException("Segment override: " + id);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.oak.plugins.segment.Segment

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.