/** * @param thread Thread. * @param c Closure. */ public void runLocalWithThreadPolicy(IgniteThread thread, Runnable c) { assert thread.stripe() >= 0 || thread.policy() != GridIoPolicy.UNDEFINED : thread; if (thread.stripe() >= 0) ctx.getStripedExecutorService().execute(thread.stripe(), c); else { try { ctx.pools().poolForPolicy(thread.policy()).execute(c); } catch (IgniteCheckedException e) { U.error(log, "Failed to get pool for policy: " + thread.policy(), e); } } }
/** * @param bucket Bucket index. * @return Page for take. */ private Stripe getPageForTake(int bucket) { Stripe[] tails = getBucket(bucket); if (tails == null || bucketsSize[bucket].get() == 0) return null; int len = tails.length; // Striped pool optimization. IgniteThread igniteThread = IgniteThread.current(); if (igniteThread != null && igniteThread.policy() == GridIoPolicy.DATA_STREAMER_POOL) { int stripeIdx = igniteThread.stripe(); assert stripeIdx != -1 : igniteThread; if (stripeIdx >= len) return null; Stripe stripe = tails[stripeIdx]; return stripe.empty ? null : stripe; } int init = randomInt(len); int cur = init; while (true) { Stripe stripe = tails[cur]; if (!stripe.empty) return stripe; if ((cur = (cur + 1) % len) == init) return null; } }
/** * @param bucket Bucket. * @param bag Reuse bag. * @return Page ID where the given page * @throws IgniteCheckedException If failed. */ private Stripe getPageForPut(int bucket, ReuseBag bag) throws IgniteCheckedException { // Striped pool optimization. IgniteThread igniteThread = IgniteThread.current(); Stripe[] tails = getBucket(bucket); if (igniteThread != null && igniteThread.policy() == GridIoPolicy.DATA_STREAMER_POOL) { int stripeIdx = igniteThread.stripe(); assert stripeIdx != -1 : igniteThread; while (tails == null || stripeIdx >= tails.length) { addStripe(bucket, bag, true); tails = getBucket(bucket); } return tails[stripeIdx]; } if (tails == null) return addStripe(bucket, bag, true); return randomTail(tails); }
/** * @param pageId Page ID. * @param page Page pointer. * @param bucket Bucket. * @param lockAttempt Lock attempts counter. * @param bag Reuse bag. * @return Page address if page is locked of {@code null} if can retry lock. * @throws IgniteCheckedException If failed. */ private long writeLockPage(long pageId, long page, int bucket, int lockAttempt, ReuseBag bag) throws IgniteCheckedException { // Striped pool optimization. IgniteThread igniteThread = IgniteThread.current(); if (igniteThread != null && igniteThread.policy() == GridIoPolicy.DATA_STREAMER_POOL) { assert igniteThread.stripe() != -1 : igniteThread; return writeLock(pageId, page); } long pageAddr = tryWriteLock(pageId, page); if (pageAddr != 0L) return pageAddr; if (lockAttempt == TRY_LOCK_ATTEMPTS) { Stripe[] stripes = getBucket(bucket); if (stripes == null || stripes.length < MAX_STRIPES_PER_BUCKET) { addStripe(bucket, bag, !isReuseBucket(bucket)); return 0L; } } return lockAttempt < TRY_LOCK_ATTEMPTS ? 0L : writeLock(pageId, page); // Must be explicitly checked further. }
/** * @param thread Thread. * @param c Closure. */ public void runLocalWithThreadPolicy(IgniteThread thread, Runnable c) { assert thread.stripe() >= 0 || thread.policy() != GridIoPolicy.UNDEFINED : thread; if (thread.stripe() >= 0) ctx.getStripedExecutorService().execute(thread.stripe(), c); else { try { ctx.pools().poolForPolicy(thread.policy()).execute(c); } catch (IgniteCheckedException e) { U.error(log, "Failed to get pool for policy: " + thread.policy(), e); } } }
/** * @param bucket Bucket index. * @return Page for take. */ private Stripe getPageForTake(int bucket) { Stripe[] tails = getBucket(bucket); if (tails == null || bucketsSize[bucket].get() == 0) return null; int len = tails.length; // Striped pool optimization. IgniteThread igniteThread = IgniteThread.current(); if (igniteThread != null && igniteThread.policy() == GridIoPolicy.DATA_STREAMER_POOL) { int stripeIdx = igniteThread.stripe(); assert stripeIdx != -1 : igniteThread; if (stripeIdx >= len) return null; Stripe stripe = tails[stripeIdx]; return stripe.empty ? null : stripe; } int init = randomInt(len); int cur = init; while (true) { Stripe stripe = tails[cur]; if (!stripe.empty) return stripe; if ((cur = (cur + 1) % len) == init) return null; } }
/** * @param bucket Bucket. * @param bag Reuse bag. * @return Page ID where the given page * @throws IgniteCheckedException If failed. */ private Stripe getPageForPut(int bucket, ReuseBag bag) throws IgniteCheckedException { // Striped pool optimization. IgniteThread igniteThread = IgniteThread.current(); Stripe[] tails = getBucket(bucket); if (igniteThread != null && igniteThread.policy() == GridIoPolicy.DATA_STREAMER_POOL) { int stripeIdx = igniteThread.stripe(); assert stripeIdx != -1 : igniteThread; while (tails == null || stripeIdx >= tails.length) { addStripe(bucket, bag, true); tails = getBucket(bucket); } return tails[stripeIdx]; } if (tails == null) return addStripe(bucket, bag, true); return randomTail(tails); }
/** * @param pageId Page ID. * @param page Page pointer. * @param bucket Bucket. * @param lockAttempt Lock attempts counter. * @param bag Reuse bag. * @return Page address if page is locked of {@code null} if can retry lock. * @throws IgniteCheckedException If failed. */ private long writeLockPage(long pageId, long page, int bucket, int lockAttempt, ReuseBag bag) throws IgniteCheckedException { // Striped pool optimization. IgniteThread igniteThread = IgniteThread.current(); if (igniteThread != null && igniteThread.policy() == GridIoPolicy.DATA_STREAMER_POOL) { assert igniteThread.stripe() != -1 : igniteThread; return writeLock(pageId, page); } long pageAddr = tryWriteLock(pageId, page); if (pageAddr != 0L) return pageAddr; if (lockAttempt == TRY_LOCK_ATTEMPTS) { Stripe[] stripes = getBucket(bucket); if (stripes == null || stripes.length < MAX_STRIPES_PER_BUCKET) { addStripe(bucket, bag, !isReuseBucket(bucket)); return 0L; } } return lockAttempt < TRY_LOCK_ATTEMPTS ? 0L : writeLock(pageId, page); // Must be explicitly checked further. }