class BulkShardCreationLimiter implements Predicate<ShardedRequests<?, ?>> {

    /**
     * Defines the maximum number of new shards per node which can be safely created before running into the
     * <p>wait_for_active_shards</p> timeout of 30sec. Value was wisely chosen after some brave testing.
     */
    static final int MAX_NEW_SHARDS_PER_NODE = 10;
    private static final Logger LOGGER = LogManager.getLogger(BulkShardCreationLimiter.class);

    private final int numDataNodes;
    private final int numberOfAllShards;

    BulkShardCreationLimiter(int numberOfShards, int numberOfReplicas, int numDataNodes) {
        this.numDataNodes = numDataNodes;
        this.numberOfAllShards = (numberOfShards + (numberOfShards * numberOfReplicas));
    }

    @Override
    public boolean test(ShardedRequests<?, ?> requests) {<FILL_FUNCTION_BODY>}
}

        if (requests.itemsByMissingIndex.isEmpty() == false) {
            int numberOfShardForAllIndices = numberOfAllShards * requests.itemsByMissingIndex.size();
            int numberOfShardsPerNode = numberOfShardForAllIndices / numDataNodes;
            if (numberOfShardsPerNode >= MAX_NEW_SHARDS_PER_NODE) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Number of NEW shards per node {} reached maximum limit of {}",
                        numberOfShardsPerNode, MAX_NEW_SHARDS_PER_NODE);
                }
                return true;
            }
        }
        return false;
    
<no_super_class>