Search in sources :

Example 1 with IgniteSemaphore

use of org.apache.ignite.IgniteSemaphore in project ignite by apache.

the class JdbcUtils method fillData.

/**
 * Common method to fill test stand with data.
 *
 * @param cfg Benchmark configuration.
 * @param ignite Ignite node.
 * @param range Data key range.
 */
public static void fillData(BenchmarkConfiguration cfg, IgniteEx ignite, long range, CacheAtomicityMode atomicMode) {
    IgniteSemaphore sem = ignite.semaphore("sql-setup", 1, true, true);
    try {
        if (sem.tryAcquire()) {
            println(cfg, "Create table...");
            StringBuilder qry = new StringBuilder("CREATE TABLE test_long (id LONG PRIMARY KEY, val LONG) WITH \"wrap_value=true");
            if (atomicMode != null)
                qry.append(", atomicity=").append(atomicMode.name());
            qry.append("\";");
            String qryStr = qry.toString();
            println(cfg, "Creating table with schema: " + qryStr);
            GridQueryProcessor qProc = ignite.context().query();
            qProc.querySqlFields(new SqlFieldsQuery(qryStr), true);
            println(cfg, "Populate data...");
            for (long l = 1; l <= range; ++l) {
                qProc.querySqlFields(new SqlFieldsQuery("INSERT INTO test_long (id, val) VALUES (?, ?)").setArgs(l, l + 1), true);
                if (l % 10000 == 0)
                    println(cfg, "Populate " + l);
            }
            qProc.querySqlFields(new SqlFieldsQuery("CREATE INDEX val_idx ON test_long (val)"), true);
            println(cfg, "Finished populating data");
        } else {
            // Acquire (wait setup by other client) and immediately release/
            println(cfg, "Waits for setup...");
            sem.acquire();
        }
    } finally {
        sem.release();
    }
}
Also used : GridQueryProcessor(org.apache.ignite.internal.processors.query.GridQueryProcessor) IgniteSemaphore(org.apache.ignite.IgniteSemaphore) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 2 with IgniteSemaphore

use of org.apache.ignite.IgniteSemaphore in project ignite by apache.

the class JdbcUtils method fillTableWithIdx.

/**
 * Common method to fill test stand with data.
 *
 * @param cfg Benchmark configuration.
 * @param ignite Ignite instance.
 * @param tblName Table name for fill and creation.
 * @param range Data key range.
 * @param atomicMode Cache creation atomicity mode.
 */
public static void fillTableWithIdx(BenchmarkConfiguration cfg, IgniteEx ignite, String tblName, long range, CacheAtomicityMode atomicMode) {
    IgniteSemaphore sem = ignite.semaphore("sql-setup", 1, true, true);
    try {
        if (sem.tryAcquire()) {
            println(cfg, "Create table...");
            StringBuilder qry = new StringBuilder(String.format("CREATE TABLE %s (", tblName) + "id LONG PRIMARY KEY, " + "DEC_COL DECIMAL, " + "DATE_COL DATE, " + "BIG_INT_COL BIGINT" + ") WITH \"wrap_value=true");
            if (atomicMode != null)
                qry.append(", atomicity=").append(atomicMode.name());
            qry.append("\";");
            String qryStr = qry.toString();
            println(cfg, "Creating table with schema: " + qryStr);
            GridQueryProcessor qProc = ignite.context().query();
            qProc.querySqlFields(new SqlFieldsQuery(qryStr), true);
            println(cfg, "Populate data...");
            for (long r = 1; r < range; ++r) {
                qProc.querySqlFields(new SqlFieldsQuery(String.format("INSERT INTO %s VALUES (?, ?, ?, ?)", tblName)).setArgs(r, new BigDecimal(r + 1), LocalDate.ofEpochDay(r), r + 2), true);
                if (r % 10000 == 0)
                    println(cfg, "Populate " + r);
            }
            qProc.querySqlFields(new SqlFieldsQuery(String.format("CREATE INDEX idx1 ON %s (DEC_COL, " + "DATE_COL) inline_size 16", tblName)), true);
            qProc.querySqlFields(new SqlFieldsQuery(String.format("CREATE INDEX idx2 ON %s (DATE_COL, " + "BIG_INT_COL) inline_size 16", tblName)), true);
            println(cfg, "Finished populating data");
        } else {
            // Acquire (wait setup by other client) and immediately release/
            println(cfg, "Waits for setup...");
            sem.acquire();
        }
    } finally {
        sem.release();
    }
}
Also used : GridQueryProcessor(org.apache.ignite.internal.processors.query.GridQueryProcessor) IgniteSemaphore(org.apache.ignite.IgniteSemaphore) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) BigDecimal(java.math.BigDecimal)

Example 3 with IgniteSemaphore

use of org.apache.ignite.IgniteSemaphore in project ignite by apache.

the class IgniteCacheAbstractBenchmark method preload.

/**
 * Preload data before benchmarking.
 */
protected void preload() {
    IgniteSemaphore semaphore = ignite().semaphore("preloadSemaphore", 1, true, true);
    semaphore.acquire();
    try {
        IgniteCache<String, Integer> preloadCache = ignite().getOrCreateCache("preloadCache");
        if (preloadCache.get("loaded") == null) {
            IgniteCompute compute = ignite().compute(ignite().cluster().forServers().forOldest());
            IgniteCache<Integer, SampleValue> cache = (IgniteCache<Integer, SampleValue>) cacheForOperation();
            Integer res = compute.apply(new Loader(cache, args, ignite()), 0);
            preloadCache.put("loaded", res);
            if (res != null)
                args.setRange(res);
        } else {
            BenchmarkUtils.println("Setting range to " + preloadCache.get("loaded"));
            args.setRange(preloadCache.get("loaded"));
        }
    } finally {
        semaphore.release();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SampleValue(org.apache.ignite.yardstick.cache.model.SampleValue) IgniteCache(org.apache.ignite.IgniteCache) IgniteSemaphore(org.apache.ignite.IgniteSemaphore) IgniteCompute(org.apache.ignite.IgniteCompute)

Example 4 with IgniteSemaphore

use of org.apache.ignite.IgniteSemaphore in project ignite by apache.

the class NativeSqlJoinQueryRangeBenchmark method setUp.

/**
 * {@inheritDoc}
 */
@Override
public void setUp(BenchmarkConfiguration cfg) throws Exception {
    super.setUp(cfg);
    IgniteSemaphore sem = ignite().semaphore("sql-setup", 1, true, true);
    try {
        if (sem.tryAcquire()) {
            qry = ((IgniteEx) ignite()).context().query();
            StringBuilder withExpr = new StringBuilder(" WITH \"AFFINITY_KEY=orgId,");
            if (args.atomicMode() != null)
                withExpr.append("atomicity=").append(args.atomicMode().name()).append(",");
            if (args.partitionedCachesNumber() == 1)
                withExpr.append("template=replicated");
            else
                withExpr.append("template=partitioned");
            withExpr.append("\"");
            qry.querySqlFields(new SqlFieldsQuery("CREATE TABLE person (id long, orgId long, name varchar, PRIMARY KEY (id, orgId))" + withExpr), true);
            withExpr = new StringBuilder(" WITH \"");
            if (args.atomicMode() != null)
                withExpr.append("atomicity=").append(args.atomicMode().name()).append(",");
            withExpr.append("template=partitioned");
            withExpr.append("\"");
            qry.querySqlFields(new SqlFieldsQuery("CREATE TABLE organization (id long primary key, name varchar)" + withExpr), true);
            for (long k = 0; k <= args.range(); ++k) {
                qry.querySqlFields(new SqlFieldsQuery("insert into person (id, orgId, name) values (?, ?, ?)").setArgs(k, k / 10, "person " + k), true).getAll();
                if (k % 10 == 0) {
                    qry.querySqlFields(new SqlFieldsQuery("insert into organization (id, name) values (?, ?)").setArgs(k / 10, "organization " + k / 10), true).getAll();
                }
                if (k % 10000 == 0)
                    println(cfg, "Populate " + k);
            }
        } else {
            // Acquire (wait setup by other client) and immediately release/
            println(cfg, "Waits for setup...");
            sem.acquire();
        }
    } finally {
        sem.release();
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteSemaphore(org.apache.ignite.IgniteSemaphore) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 5 with IgniteSemaphore

use of org.apache.ignite.IgniteSemaphore in project ignite by apache.

the class DataStructures method semaphore.

@Test
void semaphore() {
    // tag::semaphore[]
    Ignite ignite = Ignition.start();
    IgniteSemaphore semaphore = // Distributed semaphore name.
    ignite.semaphore(// Distributed semaphore name.
    "semName", // Number of permits.
    20, // Release acquired permits if node, that owned them, left topology.
    true, // Create if it doesn't exist.
    true);
    // end::semaphore[]
    ignite.close();
}
Also used : Ignite(org.apache.ignite.Ignite) IgniteSemaphore(org.apache.ignite.IgniteSemaphore) Test(org.junit.jupiter.api.Test)

Aggregations

IgniteSemaphore (org.apache.ignite.IgniteSemaphore)35 Ignite (org.apache.ignite.Ignite)19 Test (org.junit.Test)11 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 IOException (java.io.IOException)5 IgniteException (org.apache.ignite.IgniteException)5 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)4 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 IgniteCallable (org.apache.ignite.lang.IgniteCallable)4 Nullable (org.jetbrains.annotations.Nullable)4 ExpectedException (org.junit.rules.ExpectedException)4 ArrayList (java.util.ArrayList)3 Callable (java.util.concurrent.Callable)3 IgniteCountDownLatch (org.apache.ignite.IgniteCountDownLatch)3 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)3 IgniteEx (org.apache.ignite.internal.IgniteEx)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutorService (java.util.concurrent.ExecutorService)2 IgniteAtomicLong (org.apache.ignite.IgniteAtomicLong)2 IgniteAtomicReference (org.apache.ignite.IgniteAtomicReference)2