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();
}
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);
}
}
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));
}
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;
}
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);
}
Aggregations