Search in sources :

Example 41 with SB

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

the class DataPageIO method printPageLayout.

/**
     * @param pageAddr Page address.
     * @param pageSize Page size.
     * @return String representation.
     */
private String printPageLayout(long pageAddr, int pageSize) {
    int directCnt = getDirectCount(pageAddr);
    int indirectCnt = getIndirectCount(pageAddr);
    int free = getRealFreeSpace(pageAddr);
    boolean valid = directCnt >= indirectCnt;
    SB b = new SB();
    b.appendHex(PageIO.getPageId(pageAddr)).a(" [");
    int entriesSize = 0;
    for (int i = 0; i < directCnt; i++) {
        if (i != 0)
            b.a(", ");
        short item = getItem(pageAddr, i);
        if (item < ITEMS_OFF || item >= pageSize)
            valid = false;
        entriesSize += getPageEntrySize(pageAddr, item, SHOW_PAYLOAD_LEN | SHOW_LINK);
        b.a(item);
    }
    b.a("][");
    Collection<Integer> set = new HashSet<>();
    for (int i = directCnt; i < directCnt + indirectCnt; i++) {
        if (i != directCnt)
            b.a(", ");
        short item = getItem(pageAddr, i);
        int itemId = itemId(item);
        int directIdx = directItemIndex(item);
        if (!set.add(directIdx) || !set.add(itemId))
            valid = false;
        assert indirectItem(itemId, directIdx) == item;
        if (itemId < directCnt || directIdx < 0 || directIdx >= directCnt)
            valid = false;
        if (i > directCnt && itemId(getItem(pageAddr, i - 1)) >= itemId)
            valid = false;
        b.a(itemId).a('^').a(directIdx);
    }
    b.a("][free=").a(free);
    int actualFree = pageSize - ITEMS_OFF - (entriesSize + (directCnt + indirectCnt) * ITEM_SIZE);
    if (free != actualFree) {
        b.a(", actualFree=").a(actualFree);
        valid = false;
    } else
        b.a("]");
    assert valid : b.toString();
    return b.toString();
}
Also used : SB(org.apache.ignite.internal.util.typedef.internal.SB) HashSet(java.util.HashSet)

Example 42 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 43 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 44 with SB

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

the class TcpDiscoverySharedFsIpFinder method name.

/**
 * Creates file name for address.
 *
 * @param addr Node address.
 * @return Name.
 */
private String name(InetSocketAddress addr) {
    assert addr != null;
    SB sb = new SB();
    // There is no need to normalize hostname as DNS name specification doesn't allow ':' and '_' chars.
    sb.a(addr.isUnresolved() ? addr.getHostName() : normalizeAddress(addr.getAddress().getHostAddress())).a(DELIM).a(addr.getPort());
    return sb.toString();
}
Also used : SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 45 with SB

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

the class X method formatMins.

/**
 * Pretty-formatting for minutes.
 *
 * @param mins Minutes to format.
 * @return Formatted presentation of minutes.
 */
public static String formatMins(long mins) {
    assert mins >= 0;
    if (mins == 0)
        return "< 1 min";
    SB sb = new SB();
    // 1440 mins = 60 mins * 24 hours
    long dd = mins / 1440;
    if (dd > 0)
        sb.a(dd).a(dd == 1 ? " day " : " days ");
    mins %= 1440;
    long hh = mins / 60;
    if (hh > 0)
        sb.a(hh).a(hh == 1 ? " hour " : " hours ");
    mins %= 60;
    if (mins > 0)
        sb.a(mins).a(mins == 1 ? " min " : " mins ");
    return sb.toString().trim();
}
Also used : SB(org.apache.ignite.internal.util.typedef.internal.SB)

Aggregations

SB (org.apache.ignite.internal.util.typedef.internal.SB)70 Map (java.util.Map)10 HashMap (java.util.HashMap)7 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 GridStringBuilder (org.apache.ignite.internal.util.GridStringBuilder)4 InputStreamReader (java.io.InputStreamReader)3 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)3 IgfsLogger (org.apache.ignite.internal.igfs.common.IgfsLogger)3 InputStream (java.io.InputStream)2 InterruptedIOException (java.io.InterruptedIOException)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 UUID (java.util.UUID)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2