Exemplo n.º 1
0
        public static List <byte[]> ParallelFetchKeyValuesHTTP(List <ConfigState.ShardServer> shardServers, Int64 tableID, byte[] key)
        {
            var threads    = new BinaryListerThreadState[shardServers.Count];
            var serverKeys = new List <KeyValuePair <byte[], byte[]> > [shardServers.Count];

            byte[] endKey = Utils.NextKey(key);
            var    i      = 0;

            foreach (var shardServer in shardServers)
            {
                var url = Utils.HTTP.BuildUri(GetShardServerURL(shardServer),
                                              "listkeyvalues?tableID=" + tableID,
                                              "&startKey=", key,
                                              "&endKey=", key,
                                              "&count=" + 1);

                threads[i]             = new BinaryListerThreadState();
                threads[i].thread      = new Thread(new ThreadStart(threads[i].ListerThreadFunc));
                threads[i].shardServer = shardServer;
                threads[i].url         = url;
                threads[i].thread.Start();

                i += 1;
            }

            i = 0;
            foreach (var thread in threads)
            {
                thread.thread.Join();
                serverKeys[i] = thread.keyValues;

                i += 1;
            }

            var values = new List <byte[]>();

            for (i = 0; i < serverKeys.Length; i++)
            {
                if (serverKeys[i] != null && serverKeys[i].Count != 0)
                {
                    values.Add(serverKeys[i].First().Value);
                }
                else
                {
                    values.Add(null);
                }
            }
            return(values);
        }
Exemplo n.º 2
0
        public static List <KeyValuePair <byte[], byte[]> >[] ParallelFetchTableKeyValuesHTTP(List <ConfigState.ShardServer> shardServers, Int64 tableID, byte[] startKey, byte[] endKey, bool forward)
        {
            var threads         = new BinaryListerThreadState[shardServers.Count];
            var serverKeys      = new List <KeyValuePair <byte[], byte[]> > [shardServers.Count];
            var listGranularity = 100 * 1000;
            var direction       = forward ? "forward" : "backward";

            var i = 0;

            foreach (var shardServer in shardServers)
            {
                var url = Utils.HTTP.BuildUri(GetShardServerURL(shardServer),
                                              "listkeyvalues?tableID=" + tableID,
                                              "&startKey=", startKey,
                                              "&endKey=", endKey,
                                              "&count=" + listGranularity,
                                              "&direction=" + direction);

                threads[i]             = new BinaryListerThreadState();
                threads[i].thread      = new Thread(new ThreadStart(threads[i].ListerThreadFunc));
                threads[i].shardServer = shardServer;
                threads[i].url         = url;
                threads[i].thread.Start();

                i += 1;
            }

            i = 0;
            foreach (var thread in threads)
            {
                thread.thread.Join();
                serverKeys[i] = thread.keyValues;

                i += 1;
            }

            return(serverKeys);
        }
Exemplo n.º 3
0
        public static List<KeyValuePair<byte[], byte[]>>[] ParallelFetchTableKeyValuesHTTP(List<ConfigState.ShardServer> shardServers, Int64 tableID, byte[] startKey, byte[] endKey, bool forward)
        {
            var threads = new BinaryListerThreadState[shardServers.Count];
            var serverKeys = new List<KeyValuePair<byte[], byte[]>>[shardServers.Count];
            var listGranularity = 100 * 1000;
            var direction = forward ? "forward" : "backward";

            var i = 0;
            foreach (var shardServer in shardServers)
            {
                var url = Utils.HTTP.BuildUri(GetShardServerURL(shardServer),
                            "listkeyvalues?tableID=" + tableID,
                            "&startKey=", startKey,
                            "&endKey=", endKey,
                            "&count=" + listGranularity,
                            "&direction=" + direction);

                threads[i] = new BinaryListerThreadState();
                threads[i].thread = new Thread(new ThreadStart(threads[i].ListerThreadFunc));
                threads[i].shardServer = shardServer;
                threads[i].url = url;
                threads[i].thread.Start();

                i += 1;
            }

            i = 0;
            foreach (var thread in threads)
            {
                thread.thread.Join();
                serverKeys[i] = thread.keyValues;

                i += 1;
            }

            return serverKeys;
        }
Exemplo n.º 4
0
        public static List<byte[]> ParallelFetchKeyValuesHTTP(List<ConfigState.ShardServer> shardServers, Int64 tableID, byte[] key)
        {
            var threads = new BinaryListerThreadState[shardServers.Count];
            var serverKeys = new List<KeyValuePair<byte[], byte[]>>[shardServers.Count];
            byte[] endKey = Utils.NextKey(key);
            var i = 0;
            foreach (var shardServer in shardServers)
            {
                var url = Utils.HTTP.BuildUri(GetShardServerURL(shardServer),
                            "listkeyvalues?tableID=" + tableID,
                            "&startKey=", key,
                            "&endKey=", key,
                            "&count=" + 1);

                threads[i] = new BinaryListerThreadState();
                threads[i].thread = new Thread(new ThreadStart(threads[i].ListerThreadFunc));
                threads[i].shardServer = shardServer;
                threads[i].url = url;
                threads[i].thread.Start();

                i += 1;
            }

            i = 0;
            foreach (var thread in threads)
            {
                thread.thread.Join();
                serverKeys[i] = thread.keyValues;

                i += 1;
            }

            var values = new List<byte[]>();
            for (i = 0; i < serverKeys.Length; i++)
            {
                if (serverKeys[i] != null && serverKeys[i].Count != 0)
                    values.Add(serverKeys[i].First().Value);
                else
                    values.Add(null);
            }
            return values;
        }