This is an automated email from the ASF dual-hosted git repository. rnewson pushed a commit to branch user-partitioned-dbs-wip in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit e89c39a89ae345cecbbbcc100e9209b030d3d833 Author: Robert Newson <[email protected]> AuthorDate: Tue Jul 10 16:06:20 2018 +0100 map documents to shards by their partition --- src/mem3/src/mem3_shards.erl | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/mem3/src/mem3_shards.erl b/src/mem3/src/mem3_shards.erl index 0559149..18ed82e 100644 --- a/src/mem3/src/mem3_shards.erl +++ b/src/mem3/src/mem3_shards.erl @@ -67,26 +67,27 @@ for_docid(DbName, DocId) -> for_docid(DbName, DocId, []). for_docid(DbName, DocId, Options) -> - HashKey = mem3_util:docid_hash(DocId), ShardHead = #shard{ dbname = DbName, - range = ['$1', '$2'], _ = '_' }, OrderedShardHead = #ordered_shard{ dbname = DbName, - range = ['$1', '$2'], _ = '_' }, - Conditions = [{'=<', '$1', HashKey}, {'=<', HashKey, '$2'}], - ShardSpec = {ShardHead, Conditions, ['$_']}, - OrderedShardSpec = {OrderedShardHead, Conditions, ['$_']}, + ShardSpec = {ShardHead, [], ['$_']}, + OrderedShardSpec = {OrderedShardHead, [], ['$_']}, Shards = try ets:select(?SHARDS, [ShardSpec, OrderedShardSpec]) of [] -> load_shards_from_disk(DbName, DocId); - Else -> + Shards0 -> gen_server:cast(?MODULE, {cache_hit, DbName}), - Else + Options1 = case mem3:is_partitioned(hd(Shards0)) of + true -> [partitioned]; + false -> [] + end, + HashKey = mem3_util:docid_hash(DocId, Options1), + [S || S <- Shards0, in_range(S, HashKey)] catch error:badarg -> load_shards_from_disk(DbName, DocId) end, @@ -397,7 +398,11 @@ load_shards_from_db(ShardDb, DbName) -> load_shards_from_disk(DbName, DocId)-> Shards = load_shards_from_disk(DbName), - HashKey = mem3_util:docid_hash(DocId), + Options = case mem3:is_partitioned(hd(Shards)) of + true -> [partitioned]; + false -> [] + end, + HashKey = mem3_util:docid_hash(DocId, Options), [S || S <- Shards, in_range(S, HashKey)]. in_range(Shard, HashKey) ->
