Search in sources :

Example 11 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class BinaryReaderExImpl method readLine.

/** {@inheritDoc} */
@Override
public String readLine() throws IOException {
    SB sb = new SB();
    int b;
    while ((b = read()) >= 0) {
        char c = (char) b;
        switch(c) {
            case '\n':
                return sb.toString();
            case '\r':
                b = read();
                if (b < 0 || b == '\n')
                    return sb.toString();
                else
                    sb.a((char) b);
                break;
            default:
                sb.a(c);
        }
    }
    return sb.toString();
}
Also used : SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 12 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class BPlusTree method validateDownPages.

/**
     * @param pageId Page ID.
     * @param fwdId Forward ID.
     * @param lvl Level.
     * @throws IgniteCheckedException If failed.
     */
private void validateDownPages(long pageId, long fwdId, int lvl) throws IgniteCheckedException {
    long page = acquirePage(pageId);
    try {
        // No correctness guaranties.
        long pageAddr = readLock(pageId, page);
        try {
            long realPageId = BPlusIO.getPageId(pageAddr);
            if (realPageId != pageId)
                fail(new SB("ABA on page ID: ref ").appendHex(pageId).a(", buf ").appendHex(realPageId));
            BPlusIO<L> io = io(pageAddr);
            if (// Leaf pages only at the level 0.
            io.isLeaf() != (lvl == 0))
                fail("Leaf level mismatch: " + lvl);
            long actualFwdId = io.getForward(pageAddr);
            if (actualFwdId != fwdId)
                fail(new SB("Triangle: expected fwd ").appendHex(fwdId).a(", actual fwd ").appendHex(actualFwdId));
            int cnt = io.getCount(pageAddr);
            if (cnt < 0)
                fail("Negative count: " + cnt);
            if (io.isLeaf()) {
                if (cnt == 0 && getRootLevel() != 0)
                    fail("Empty leaf page.");
            } else {
                // Recursively go down if we are on inner level.
                for (int i = 0; i < cnt; i++) validateDownPages(inner(io).getLeft(pageAddr, i), inner(io).getRight(pageAddr, i), lvl - 1);
                if (fwdId != 0) {
                    // For the rightmost child ask neighbor.
                    long fwdId0 = fwdId;
                    long fwdPage = acquirePage(fwdId0);
                    try {
                        // No correctness guaranties.
                        long fwdPageAddr = readLock(fwdId0, fwdPage);
                        try {
                            if (io(fwdPageAddr) != io)
                                fail("IO on the same level must be the same");
                            fwdId = inner(io).getLeft(fwdPageAddr, 0);
                        } finally {
                            readUnlock(fwdId0, fwdPage, fwdPageAddr);
                        }
                    } finally {
                        releasePage(fwdId0, fwdPage);
                    }
                }
                // The same as io.getRight(cnt - 1) but works for routing pages.
                long leftId = inner(io).getLeft(pageAddr, cnt);
                validateDownPages(leftId, fwdId, lvl - 1);
            }
        } finally {
            readUnlock(pageId, page, pageAddr);
        }
    } finally {
        releasePage(pageId, page);
    }
}
Also used : SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 13 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class BPlusTree method validateFirstPage.

/**
     * @param metaId Meta page ID.
     * @param metaPage Meta page pointer.
     * @param lvl Level.
     * @throws IgniteCheckedException If failed.
     */
private void validateFirstPage(long metaId, long metaPage, int lvl) throws IgniteCheckedException {
    if (lvl == 0)
        fail("Leaf level: " + lvl);
    long pageId = getFirstPageId(metaId, metaPage, lvl);
    long leftmostChildId;
    long page = acquirePage(pageId);
    try {
        // No correctness guaranties.
        long pageAddr = readLock(pageId, page);
        try {
            BPlusIO<L> io = io(pageAddr);
            if (io.isLeaf())
                fail("Leaf.");
            leftmostChildId = inner(io).getLeft(pageAddr, 0);
        } finally {
            readUnlock(pageId, page, pageAddr);
        }
    } finally {
        releasePage(pageId, page);
    }
    long firstDownPageId = getFirstPageId(metaId, metaPage, lvl - 1);
    if (firstDownPageId != leftmostChildId)
        fail(new SB("First: meta ").appendHex(firstDownPageId).a(", child ").appendHex(leftmostChildId));
}
Also used : SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 14 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class GridChangeStateCommandHandler method handleAsync.

/** {@inheritDoc} */
@Override
public IgniteInternalFuture<GridRestResponse> handleAsync(GridRestRequest restRest) {
    GridRestChangeStateRequest req = (GridRestChangeStateRequest) restRest;
    final GridFutureAdapter<GridRestResponse> fut = new GridFutureAdapter<>();
    final GridRestResponse res = new GridRestResponse();
    try {
        if (req.command().equals(CLUSTER_CURRENT_STATE)) {
            Boolean currentState = ctx.state().active();
            res.setResponse(currentState);
        } else
            ctx.state().changeGlobalState(req.active()).get();
        fut.onDone(res);
    } catch (Exception e) {
        SB sb = new SB();
        sb.a(e.getMessage()).a("\n").a("suppressed: \n");
        for (Throwable t : e.getSuppressed()) sb.a(t.getMessage()).a("\n");
        res.setError(sb.toString());
        fut.onDone(res);
    }
    return fut;
}
Also used : GridRestChangeStateRequest(org.apache.ignite.internal.processors.rest.request.GridRestChangeStateRequest) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) GridRestResponse(org.apache.ignite.internal.processors.rest.GridRestResponse) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 15 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class GridIntList method toString.

/** {@inheritDoc} */
@Override
public String toString() {
    SB b = new SB("[");
    for (int i = 0; i < idx; i++) {
        if (i != 0)
            b.a(',');
        b.a(arr[i]);
    }
    b.a(']');
    return S.toString(GridIntList.class, this, "arr", b);
}
Also used : SB(org.apache.ignite.internal.util.typedef.internal.SB)

Aggregations

SB (org.apache.ignite.internal.util.typedef.internal.SB)57 Map (java.util.Map)8 HashMap (java.util.HashMap)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 GridStringBuilder (org.apache.ignite.internal.util.GridStringBuilder)4 IgfsLogger (org.apache.ignite.internal.igfs.common.IgfsLogger)3 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 LineNumberReader (java.io.LineNumberReader)2 URL (java.net.URL)2 URLConnection (java.net.URLConnection)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ObjectName (javax.management.ObjectName)2 BinaryObject (org.apache.ignite.binary.BinaryObject)2 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)2