示例#1
0
        public IList <string> SelectShardIds(ShardResolutionStrategyData srsd)
        {
            if (srsd.EntityType == typeof(User))
            {
                return new[] { "Users" }
            }
            ;
            if (srsd.EntityType == typeof(Blog))
            {
                return new[] { "Blogs" }
            }
            ;
            if (srsd.EntityType == typeof(Post))
            {
                if (srsd.Key == null)                 // general query
                {
                    return(Enumerable.Range(0, numberOfShardsForPosts).Select(i => "Posts #" + (i + 1)).ToArray());
                }
                // we can optimize better, since the key has the shard id
                // key structure is 'posts' / 'shard id' / 'post id'
                var parts = srsd.Key.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

                return(new[] { "Posts #" + parts[1] });
            }

            throw new ArgumentException("Cannot get shard id for '" + srsd.EntityType +
                                        "' because it is not a User, Blog or Post");
        }
    }
}
示例#2
0
     public IList <string> SelectShardIds(ShardResolutionStrategyData srsd)
     {
         if (srsd.Key != null)
         {
             return new[] { srsd.Key.Split('/')[1] }
         }
         ;
         return(null);
     }
 }
示例#3
0
        private IDocumentSession[] GetAppropriateShardedSessions <T>(string key)
        {
            var sessionIds =
                shardStrategy.ShardResolutionStrategy.SelectShardIds(ShardResolutionStrategyData.BuildFrom(typeof(T), key));

            IDocumentSession[] documentSessions;
            if (sessionIds != null)
            {
                documentSessions = shardSessions.Where(session => sessionIds.Contains(session.Advanced.StoreIdentifier)).ToArray();
            }
            else
            {
                documentSessions = shardSessions;
            }
            return(documentSessions);
        }
        public IList <string> SelectShardIds(ShardResolutionStrategyData srsd)
        {
            if (srsd.EntityType == typeof(User))
            {
                return new[] { "Users" }
            }
            ;
            if (srsd.EntityType == typeof(Post))
            {
                return new[] { "Post" }
            }
            ;

            throw new ArgumentException("Cannot get shard id for '" + srsd.EntityType + "' because it is not a User or Post");
        }
    }
}