Search in sources :

Example 11 with GridStringBuilder

use of org.apache.ignite.internal.util.GridStringBuilder in project ignite by apache.

the class AbstractSchemaSelfTest method dynamicIndexCreate.

/**
 * Synchronously create index.
 *
 * @param node Ignite node.
 * @param cacheName Cache name.
 * @param tblName Table name.
 * @param idx Index.
 * @param ifNotExists When set to true operation will fail if index already exists.
 * @param parallel Parallelism level.
 * @throws Exception If failed.
 */
void dynamicIndexCreate(Ignite node, String cacheName, String tblName, QueryIndex idx, boolean ifNotExists, int parallel) throws Exception {
    GridStringBuilder sql = new SB("CREATE INDEX ").a(ifNotExists ? "IF NOT EXISTS " : "").a(idx.getName()).a(" ON ").a(tblName).a(" (");
    boolean first = true;
    for (Map.Entry<String, Boolean> fieldEntry : idx.getFields().entrySet()) {
        if (first)
            first = false;
        else
            sql.a(", ");
        String name = fieldEntry.getKey();
        boolean asc = fieldEntry.getValue();
        sql.a(name).a(" ").a(asc ? "ASC" : "DESC");
    }
    sql.a(')');
    if (idx.getInlineSize() != QueryIndex.DFLT_INLINE_SIZE)
        sql.a(" INLINE_SIZE ").a(idx.getInlineSize());
    if (parallel != 0)
        sql.a(" PARALLEL ").a(parallel);
    executeSql(node, cacheName, sql.toString());
}
Also used : GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 12 with GridStringBuilder

use of org.apache.ignite.internal.util.GridStringBuilder in project ignite by apache.

the class AbstractSchemaSelfTest method dynamicIndexCreate.

/**
     * Synchronously create index.
     *
     * @param node Ignite node.
     * @param cacheName Cache name.
     * @param tblName Table name.
     * @param idx Index.
     * @param ifNotExists When set to true operation will fail if index already exists.
     * @throws Exception If failed.
     */
protected void dynamicIndexCreate(Ignite node, String cacheName, String tblName, QueryIndex idx, boolean ifNotExists) throws Exception {
    GridStringBuilder sql = new SB("CREATE INDEX ").a(ifNotExists ? "IF NOT EXISTS " : "").a(idx.getName()).a(" ON ").a(tblName).a(" (");
    boolean first = true;
    for (Map.Entry<String, Boolean> fieldEntry : idx.getFields().entrySet()) {
        if (first)
            first = false;
        else
            sql.a(", ");
        String name = fieldEntry.getKey();
        boolean asc = fieldEntry.getValue();
        sql.a(name).a(" ").a(asc ? "ASC" : "DESC");
    }
    sql.a(')');
    executeSql(node, cacheName, sql.toString());
}
Also used : GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 13 with GridStringBuilder

use of org.apache.ignite.internal.util.GridStringBuilder in project ignite by apache.

the class CLIArgumentParser method usage.

/**
 * Returns usage description.
 *
 * @return Usage.
 */
public String usage() {
    GridStringBuilder sb = new GridStringBuilder("Usage: ");
    for (CLIArgument arg : argConfiguration.values()) sb.a(argNameForUsage(arg)).a(" ");
    for (CLIArgument arg : argConfiguration.values()) {
        Object dfltVal = null;
        try {
            dfltVal = arg.defaultValueSupplier().apply(this);
        } catch (Exception ignored) {
        /* No op. */
        }
        sb.a("\n\n").a(arg.name()).a(": ").a(arg.usage());
        if (arg.optional())
            sb.a(" Default value: ").a(dfltVal);
    }
    return sb.toString();
}
Also used : GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) IgniteException(org.apache.ignite.IgniteException)

Example 14 with GridStringBuilder

use of org.apache.ignite.internal.util.GridStringBuilder in project ignite by apache.

the class PageIO method printPage.

/**
 * @param addr Address.
 */
public static String printPage(long addr, int pageSize) {
    GridStringBuilder sb = new GridStringBuilder("Header [\n\ttype=");
    try {
        PageIO io = getPageIO(addr);
        sb.a(getType(addr)).a(" (").a(io.getClass().getSimpleName()).a("),\n\tver=").a(getVersion(addr)).a(",\n\tcrc=").a(getCrc(addr)).a(",\n\t").a(PageIdUtils.toDetailString(getPageId(addr))).a("\n],\n");
        if (getCompressionType(addr) != 0) {
            sb.a("CompressedPage[\n\tcompressionType=").a(getCompressionType(addr)).a(",\n\tcompressedSize=").a(getCompressedSize(addr)).a(",\n\tcompactedSize=").a(getCompactedSize(addr)).a("\n]");
        } else
            io.printPage(addr, pageSize, sb);
    } catch (IgniteCheckedException e) {
        sb.a("Failed to print page: ").a(e.getMessage());
    }
    return sb.toString();
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) MetastoreDataPageIO(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetastoreDataPageIO)

Example 15 with GridStringBuilder

use of org.apache.ignite.internal.util.GridStringBuilder in project ignite by apache.

the class GridCachePartitionExchangeManager method longRunningTransactionWarning.

/**
 * Builds warning string for long running transaction.
 *
 * @param tx Transaction.
 * @param curTime Current timestamp.
 * @return Warning string.
 */
private static String longRunningTransactionWarning(IgniteInternalTx tx, long curTime) {
    GridStringBuilder warning = new GridStringBuilder().a(">>> Transaction [startTime=").a(formatTime(tx.startTime())).a(", curTime=").a(formatTime(curTime));
    if (tx instanceof GridNearTxLocal) {
        GridNearTxLocal nearTxLoc = (GridNearTxLocal) tx;
        long sysTimeCurr = nearTxLoc.systemTimeCurrent();
        // in some cases totalTimeMillis can be less than systemTimeMillis, as they are calculated with different precision
        long userTime = Math.max(curTime - nearTxLoc.startTime() - sysTimeCurr, 0);
        warning.a(", systemTime=").a(sysTimeCurr).a(", userTime=").a(userTime);
    }
    warning.a(", tx=").a(tx).a("]");
    return warning.toString();
}
Also used : GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)

Aggregations

GridStringBuilder (org.apache.ignite.internal.util.GridStringBuilder)19 SB (org.apache.ignite.internal.util.typedef.internal.SB)8 Map (java.util.Map)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteException (org.apache.ignite.IgniteException)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Ignite (org.apache.ignite.Ignite)1 IgniteCluster (org.apache.ignite.IgniteCluster)1 BinaryObject (org.apache.ignite.binary.BinaryObject)1 QueryEntity (org.apache.ignite.cache.QueryEntity)1 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)1