----------------------------------- Sharding Functionality
420299
public void createShard() {
        VertexElement shardVertex = vertex().tx().addVertexElement(Schema.BaseType.SHARD);
        Shard shard = vertex().tx().factory().buildShard(this, shardVertex);
        //store current shard id as a property of the type
        vertex().property(Schema.VertexProperty.CURRENT_SHARD, shard.id());
        currentShard.set(shard);

        //Updated the cached shard count if needed
        if (shardCount.isPresent()) {
            shardCount.set(shardCount() + 1);
        }
    }
897313
def _get_shard(self, shard):
        """"""
        @wraps(API_WRAPPER._get_shard)
        def get_shard(*arg, **kwargs):
            """Gets the shard '{}'""".format(shard)
            return self.get_shards(Shard(shard, *arg, **kwargs))
        return get_shard
1207779
static ByteBuffer getRowKeyRaw(int shardId, long tableUuid, byte[] contentKeyBytes) {
        checkArgument(shardId >= 0 && shardId < 256);

        // Assemble a single array which is "1 byte shard id + 8 byte table uuid + n-byte content key".
        ByteBuffer rowKey = ByteBuffer.allocate(9 + contentKeyBytes.length);
        rowKey.put((byte) shardId);
        rowKey.putLong(tableUuid);
        rowKey.put(contentKeyBytes);

        rowKey.flip();
        return rowKey;
    }
606143
def with_default_and_all(continue_on_error = false)
      ([default_shard] + cluster.shards).map do |shard|
        begin
          with_shard(shard) {
            yield
          }
        rescue Exception => err
          unless continue_on_error
            raise err
          end
          err
        end
      end
    end
1262735
public function geoHashGrid($alias, $field, $precision, $size = null, $shardSize = null)
    {
        $aggregation = new GeoHashGridAggregation($alias, $field, $precision, $size, $shardSize);

        $this->append($aggregation);
    }
713722
private void setDbCodeCollection() {
        dbCodeCollection = new ArrayList<String>(shardingNum);
        int codeLength = Integer.toBinaryString(shardingNum - 1).length();
        for (int i = 0; i < shardingNum; i++) {
            String dbcode = Integer.toBinaryString(i);
            for (int j = dbcode.length(); j < codeLength; j++) {
                dbcode = "0" + dbcode;
            }
            dbCodeCollection.add(i, dbcode);
        }
    }
671410
function shard_table($id)
    {
        if (empty($this->_table_before_shard))
        {
            $this->_table_before_shard = $this->table;
        }
        $table_id = intval($id / $this->tablesize);
        $this->table = $this->_table_before_shard . '_' . $table_id;
    }
194100
int numShardsIOwn() {
        final boolean[] shards = iOwn.get();
        if (shards == null)
            return 0;
        return (int) IntStream.range(0, shards.length).mapToObj(i -> Boolean.valueOf(shards[i])).filter(b -> b.booleanValue()).count();
    }
658931
def _compute(self, feed_dict, shard):
        

        try:
            descriptor, enq = self._tfrun(self._tf_expr[shard], feed_dict=feed_dict)
            self._inputs_waiting.decrement(shard)

        except Exception as e:
            montblanc.log.exception("Compute Exception")
            raise
403611
private boolean updateShardedObjectMove(DBObject dbObj) {
        DBObject currDBObj = SpiderService.instance().getObject(m_tableDef, dbObj.getObjectID());
        m_logger.debug("Update forcing move of object {} from shard {} to shard {}",
                       new Object[]{dbObj.getObjectID(),
                                    m_tableDef.getShardNumber(currDBObj),
                                    m_tableDef.getShardNumber(dbObj)});
        
        deleteObject(currDBObj);
        mergeAllFieldValues(dbObj, currDBObj);
        addBrandNewObject(currDBObj);
        return true;
    }
762361
private void cacheShardValue(TableDefinition tableDef,
                                 Integer         shardNumber,
                                 Date            shardStart) {
        // Get or create the app name -> table map
        String appName = tableDef.getAppDef().getAppName();
        Map<String, Map<Integer, Date>> tableShardNumberMap = m_appShardMap.get(appName);
        if (tableShardNumberMap == null) {
            tableShardNumberMap = new HashMap<String, Map<Integer,Date>>();
            m_appShardMap.put(appName, tableShardNumberMap);
        }
        
        // Get or create the table name -> shard number map
        String tableName = tableDef.getTableName();
        Map<Integer, Date> shardNumberMap = tableShardNumberMap.get(tableName);
        if (shardNumberMap == null) {
            shardNumberMap = new HashMap<Integer, Date>();
            tableShardNumberMap.put(tableName, shardNumberMap);
        }
        
        // Add the shard number -> start date
        shardNumberMap.put(shardNumber, shardStart);
        m_logger.debug("Sharding date for {}.{} shard #{} set to: {} ({})",
                       new Object[]{appName, tableName, shardNumber, shardStart.getTime(), Utils.formatDateUTC(shardStart)});
    }
1262025
private boolean objectIsChangingShards(DBObject dbObj, Map<String, String> currScalarMap) {
        if (!m_tableDef.isSharded()) {
            return false;
        }
        
        // If object had no prior sharding-field value, it is considered in shard 0.
        int oldShardNumber = 0;
        String shardingFieldName = m_tableDef.getShardingField().getName();
        String currShardFieldValue = currScalarMap.get(shardingFieldName);
        if (currShardFieldValue != null) {
            oldShardNumber = m_tableDef.computeShardNumber(Utils.dateFromString(currShardFieldValue));
        }
        
        // Propagate old sharding-field value if not being updated now.
        int newShardNumber = m_tableDef.getShardNumber(dbObj);
        String newShardFieldValue = dbObj.getFieldValue(shardingFieldName);
        if (newShardFieldValue == null && currShardFieldValue != null) {
            dbObj.addFieldValue(shardingFieldName, currShardFieldValue);
            return false;
        }
        
        // May or may not be moving to a new shard.
        return oldShardNumber != newShardNumber;
    }
1005340
public boolean hasLegacyShards(ByteBuffer context)
    {
        int totalCount = (context.remaining() - headerLength(context)) / STEP_LENGTH;
        int localAndGlobalCount = Math.abs(context.getShort(context.position()));

        if (localAndGlobalCount < totalCount)
            return true; // remote shard(s) present

        for (int i = 0; i < localAndGlobalCount; i++)
            if (context.getShort(context.position() + HEADER_SIZE_LENGTH + i * HEADER_ELT_LENGTH) >= 0)
                return true; // found a local shard

        return false;
    }
509773
private BucketShards computeMerged()
            throws SQLException
    {
        if (resultSet.isAfterLast()) {
            return endOfData();
        }
        if (first) {
            first = false;
            if (!resultSet.next()) {
                return endOfData();
            }
        }

        int bucketNumber = resultSet.getInt("bucket_number");
        ImmutableSet.Builder<ShardNodes> shards = ImmutableSet.builder();

        do {
            UUID shardUuid = uuidFromBytes(resultSet.getBytes("shard_uuid"));
            int bucket = resultSet.getInt("bucket_number");
            Set<String> nodeIdentifiers = ImmutableSet.of(getBucketNode(bucket));

            shards.add(new ShardNodes(shardUuid, nodeIdentifiers));
        }
        while (resultSet.next() && resultSet.getInt("bucket_number") == bucketNumber);

        return new BucketShards(OptionalInt.of(bucketNumber), shards.build());
    }
963424
@Override
  protected TermsByQueryShardRequest newShardRequest(int numShards, ShardRouting shard, TermsByQueryRequest request) {
    String[] filteringAliases = indexNameExpressionResolver.filteringAliases(clusterService.state(), shard.index(), request.indices());
    return new TermsByQueryShardRequest(shard.shardId(), filteringAliases, request);
  }
915357
public static boolean is_shar(String str)
    {

        if (str.equals("S") || str.equals("z") || str.equals("s")) return true;

        return false;
    }
267583
public static void checkShard(Olap olap, ApplicationDefinition appDef, String shard) {
        VDirectory appDir = olap.getRoot(appDef);
        VDirectory shardDir = appDir.getDirectory(shard);
        checkShard(shardDir);
    }