Esempio n. 1
0
        /** Greedy routing.  gen_arg is the Address of the destination
         */
        public override void GenerateTree(Channel q, MapReduceArgs mr_args)
        {
            object gen_arg = mr_args.GenArg;

            Log("{0}: {1}, greedy generator called, arg: {2}.",
                this.TaskName, _node.Address, gen_arg);
            string          address      = gen_arg as string;
            AHAddress       a            = (AHAddress)AddressParser.Parse(address);
            ArrayList       retval       = new ArrayList();
            ConnectionTable tab          = _node.ConnectionTable;
            ConnectionList  structs      = tab.GetConnections(ConnectionType.Structured);
            Connection      next_closest = structs.GetNearestTo((AHAddress)_node.Address, a);

            if (next_closest != null)
            {
                //arguments do not change at all
                MapReduceInfo mr_info = new MapReduceInfo(next_closest.Edge, mr_args);
                retval.Add(mr_info);
            }

            Log("{0}: {1}, greedy generator returning: {2} senders.",
                this.TaskName, _node.Address, retval.Count);
            //Send the result:
            q.Enqueue(retval.ToArray(typeof(MapReduceInfo)));
        }
Esempio n. 2
0
        public override void GenerateTree(Channel q, MapReduceArgs args)
        {
            Channel result = new Channel(1, q);

            result.CloseEvent += this.TreeHandler;
            _node.Rpc.Invoke(_tree.First, result, _tree.Second, args.ToHashtable());
        }
Esempio n. 3
0
        /**
         * Generates tree for bounded broadcast. Algorithm works as follows:
         * The goal is to broadcast to all nodes in range (start, end).
         * Given a range (a, b), determine all connections that belong to this range.
         * Let the left connections be l_1, l_2, ..... l_n.
         * Let the right connections be r_1, r_2, ... , r_n.
         * To left connection l_i assign the range [b_{i-1}, b_i).
         * To right connection r_i assign the range [r_i, r_{i-1}]
         * To the connection ln assign range [l_{n-1}, end)
         * To the connection rn assign range (start, r_{n-1}]
         */
        public override void GenerateTree(Channel q, MapReduceArgs mr_args)
        {
            ArrayList gen_list    = mr_args.GenArg as ArrayList;
            string    start_range = gen_list[0] as string;
            AHAddress start_addr  = (AHAddress)AddressParser.Parse(start_range);
            AHAddress end_addr;
            string    end_range;

            /// If users do not specify an end range, this method understands
            /// that users intend to broadcasting the whole range.
            /// Thus, the address of end range is set to (start_address - 2),
            /// the farthest address from the start_addr.
            if (gen_list.Count < 2)
            {
                BigInteger start_int = start_addr.ToBigInteger();
                BigInteger end_int   = start_int - 2;
                end_addr  = new AHAddress(end_int);
                end_range = end_addr.ToString();
            }
            else
            {
                end_range = gen_list[1] as string;
                end_addr  = (AHAddress)AddressParser.Parse(end_range);
            }
            Log("generating child tree, range start: {0}, range end: {1}.", start_range, end_range);
            //we are at the start node, here we go:
            ConnectionTable      tab     = _node.ConnectionTable;
            ConnectionList       structs = tab.GetConnections(ConnectionType.Structured);
            List <MapReduceInfo> retval  = new List <MapReduceInfo>();

            if (InRange(_this_addr, start_addr, end_addr))
            {
                if (structs.Count > 0)
                {
                    //make connection list in the range.
                    //left connection list is a list of neighbors which are in the range (this node, end of range)
                    //right connection list is a list of neighbors which are in the range (start of range, this node)
                    Brunet.Collections.Pair <List <Connection>, List <Connection> > cons = GetConnectionInfo(_this_addr, start_addr, end_addr, structs);
                    List <Connection> left_cons  = cons.First as List <Connection>;
                    List <Connection> right_cons = cons.Second as List <Connection>;
                    //PrintConnectionList(left_cons);
                    //PrintConnectionList(right_cons);
                    retval = GenerateTreeInRange(start_addr, end_addr, left_cons, true, mr_args);
                    List <MapReduceInfo> ret_right = GenerateTreeInRange(start_addr, end_addr, right_cons, false, mr_args);
                    retval.AddRange(ret_right);
                }
                else //this node is a leaf node.
                //MapReduceInfo mr_info = null;
                //retval.Add(mr_info);
                //Console.WriteLine("no connection in the range: return null info");
                {
                }
            }
            else // _node is out of range. Just pass it to the closest to the middle of range.
            {
                retval = GenerateTreeOutRange(start_addr, end_addr, mr_args);
            }
            q.Enqueue(retval.ToArray());
        }
Esempio n. 4
0
 /**
  * Constructor
  * @param node local node
  * @param state RPC related state.
  * @param task map-reduce task.
  * @param args arguments to the map reduce task.
  */
 public MapReduceComputation(Node node, object state,
                             MapReduceTask task,
                             MapReduceArgs args)
 {
     _node             = node;
     _rpc              = node.Rpc;
     _mr_request_state = state;
     _mr_task          = task;
     _mr_args          = args;
     //Here is our state variable:
     _state  = new State();
     _result = State.DEFAULT_OBJ;
 }
Esempio n. 5
0
 /** Greedy routing.  gen_arg is the Address of the destination
  */
 public override void GenerateTree(Channel q, MapReduceArgs mr_args) {
   object gen_arg = mr_args.GenArg;
   Log("{0}: {1}, greedy generator called, arg: {2}.", 
       this.TaskName, _node.Address, gen_arg);
   string address = gen_arg as string;
   AHAddress a =  (AHAddress) AddressParser.Parse(address);
   ArrayList retval = new ArrayList();
   ConnectionTable tab = _node.ConnectionTable;
   ConnectionList structs = tab.GetConnections(ConnectionType.Structured);
   Connection next_closest = structs.GetNearestTo((AHAddress) _node.Address, a);
   if (next_closest != null) {
     //arguments do not change at all
     MapReduceInfo mr_info = new MapReduceInfo(next_closest.State.Edge, mr_args);
     retval.Add(mr_info);
   }
   
   Log("{0}: {1}, greedy generator returning: {2} senders.", 
       this.TaskName, _node.Address, retval.Count);
   //Send the result:
   q.Enqueue(retval.ToArray(typeof(MapReduceInfo)));
 }
Esempio n. 6
0
        protected void TreeHandler(object o, EventArgs eargs)
        {
            Channel result = (Channel)o;
            Channel q      = (Channel)result.State;

            try {
                RpcResult r    = (RpcResult)result.Dequeue();
                var       mris = new List <MapReduceInfo>();
                foreach (IDictionary d in (IList)r.Result)
                {
                    var uri    = (string)d["sender"];
                    var sender = SenderFactory.CreateInstance(_node, uri);
                    var args   = new MapReduceArgs((IDictionary)d["args"]);
                    mris.Add(new MapReduceInfo(sender, args));
                }
                q.Enqueue(mris.ToArray());
            }
            catch (Exception x) {
                //Some kind of problem:
                q.Enqueue(x);
            }
        }
Esempio n. 7
0
 public MapReduceInfo(ISender sender, MapReduceArgs args)
 {
     Sender = sender;
     Args   = args;
 }
Esempio n. 8
0
        /**
         * This dispatches the particular methods this class provides.
         * Currently, the only invokable method is:
         * "Start".
         */
        public void HandleRpc(ISender caller, string method, IList args, object req_state)
        {
            int part_idx = method.IndexOf(':');

            if (part_idx == -1)
            {
                if (method == "Start")
                {
                    IDictionary   ht        = (IDictionary)args[0];
                    MapReduceArgs mr_args   = new MapReduceArgs(ht);
                    string        task_name = mr_args.TaskName;
                    MapReduceTask task;
                    if (_name_to_task.TryGetValue(task_name, out task))
                    {
                        MapReduceComputation mr = new MapReduceComputation(_node, req_state, task, mr_args);
                        mr.Start();
                    }
                    else
                    {
                        throw new AdrException(-32608, "No mapreduce task with name: " + task_name);
                    }
                }
                else if (method == "AddHandler")
                {
                    //Make sure this is local:
                    ISender tmp_call = caller;
                    bool    islocal  = tmp_call is Node;
                    while (!islocal && tmp_call is IWrappingSender)
                    {
                        tmp_call = ((IWrappingSender)tmp_call).WrappedSender;
                        islocal  = tmp_call is Node;
                    }
                    if (!islocal)
                    {
                        throw new AdrException(-32601, "AddHandler only valid for local callers");
                    }
                    SubscribeTask(new RpcMapReduceTask(_node, (IDictionary)args[0]));
                    _rpc.SendResult(req_state, null);
                }
                else
                {
                    throw new AdrException(-32601, "No Handler for method: " + method);
                }
            }
            else
            {
                //This is a reference to a specific part of a task:
                string        part      = method.Substring(0, part_idx);
                string        task_name = method.Substring(part_idx + 1);
                MapReduceTask task;
                if (false == _name_to_task.TryGetValue(task_name, out task))
                {
                    throw new AdrException(-32608, "No mapreduce task with name: " + task_name);
                }
                if (part == "tree")
                {
                    var mra = new MapReduceArgs((IDictionary)args[0]);

                    var tree_res = new Channel(1, req_state);
                    tree_res.CloseEvent += this.HandleTree;
                    task.GenerateTree(tree_res, mra);
                }
                else if (part == "reduce")
                {
                    //Prepare the RpcResult:
                    var     rres_d = (IDictionary)args[2];
                    ISender send   = SenderFactory.CreateInstance(_node, (string)rres_d["sender"]);
                    var     rres   = new RpcResult(send, rres_d["result"]);

                    Channel reduce_res = new Channel(1, req_state);
                    reduce_res.CloseEvent += this.HandleReduce;
                    task.Reduce(reduce_res, args[0], args[1], rres);
                }
                else if (part == "map")
                {
                    Channel map_res = new Channel(1, req_state);
                    map_res.CloseEvent += this.HandleMap;
                    task.Map(map_res, args[0]);
                }
                else
                {
                    throw new AdrException(-32608,
                                           String.Format("No mapreduce task({0}) part with name: {1}", task_name, part));
                }
            }
        }
Esempio n. 9
0
 public override void GenerateTree(Channel q, MapReduceArgs args) {
   Channel result = new Channel(1, q);
   result.CloseEvent += this.TreeHandler;
   _node.Rpc.Invoke(_tree.First, result, _tree.Second, args.ToHashtable());
 }
Esempio n. 10
0
 /**
  * Generate tree within the range.
  * return list of MapReduceInfo
  */
 private List<MapReduceInfo> GenerateTreeInRange(AHAddress start, AHAddress end, List<Connection> cons, bool left, MapReduceArgs mr_args) {
   //Divide the range and trigger bounded broadcasting again in divided range starting with neighbor.
   //Deivided ranges are (start, n_1), (n_1, n_2), ... , (n_m, end)
   AHAddress this_minus2 = new AHAddress(_this_addr.ToBigInteger()-2);
   AHAddress this_plus2 = new AHAddress(_this_addr.ToBigInteger()+2);
   List<MapReduceInfo> retval = new List<MapReduceInfo>();
   if (cons.Count != 0) //make sure if connection list is not empty!
   {
     //con_list is sorted.
     AHAddress last;
     if (left) {
       last = end;
     }
     else {
       last = start;
     }
     string rg_start, rg_end;
     //the first element of cons is the nearest.
     //Let's start with the farthest neighbor first.
     for (int i = (cons.Count-1); i >= 0; i--) {
       ArrayList gen_arg = new ArrayList();
       Connection next_c = cons[i];
       AHAddress next_addr = (AHAddress)next_c.Address;
       ISender sender = next_c.State.Edge;
       if (i==0) {  // The last bit
         if (left) {
           // the left nearest neighbor 
           rg_start = this_plus2.ToString();
           rg_end = last.ToString();
         }
         else {
           // the right nearest neighbor
           rg_start = last.ToString();
           rg_end = this_minus2.ToString();
         }
       }
       else {
         if (left) { //left connections
           rg_start = next_addr.ToString();
           rg_end = last.ToString();
         }
         else {  //right connections
           rg_start = last.ToString();
           rg_end = next_addr.ToString();
         }
       }
       gen_arg.Add(rg_start);
       gen_arg.Add(rg_end);
       MapReduceInfo mr_info = new MapReduceInfo( sender,
        		                              new MapReduceArgs(this.TaskName,
       				               	             mr_args.MapArg,
       							     gen_arg,
       							     mr_args.ReduceArg));
       Log("{0}: {1}, adding address: {2} to sender list, range start: {3}, range end: {4}",
       			    this.TaskName, _node.Address, next_c.Address,
       			    gen_arg[0], gen_arg[1]);
       if (left) {
         last = new AHAddress(next_addr.ToBigInteger()-2);
       }
       else {
         last = new AHAddress(next_addr.ToBigInteger()+2);
       }
       retval.Add(mr_info);
     }
   }
   return retval;
 }    
Esempio n. 11
0
        /**
         * When a node is out of the range, this method is called.
         * This method tries to find the nearest node to the middle of range using greedty algorithm.
         * return list of MapReduceInfo
         */
        private List <MapReduceInfo> GenerateTreeOutRange(AHAddress start, AHAddress end, MapReduceArgs mr_args)
        {
            List <MapReduceInfo> retval    = new List <MapReduceInfo>();
            BigInteger           up        = start.ToBigInteger();
            BigInteger           down      = end.ToBigInteger();
            BigInteger           mid_range = (up + down) / 2;

            if (mid_range % 2 == 1)
            {
                mid_range = mid_range - 1;
            }
            AHAddress mid_addr = new AHAddress(mid_range);

            //if (!mid_addr.IsBetweenFromLeft(start, end) ) {
            if (!InRange(mid_addr, start, end))
            {
                mid_range += Address.Half;
                mid_addr   = new AHAddress(mid_range);
            }
            ArrayList gen_arg = new ArrayList();

            if (NextGreedyClosest(mid_addr) != null)
            {
                AHGreedySender ags         = new AHGreedySender(_node, mid_addr);
                string         start_range = start.ToString();
                string         end_range   = end.ToString();
                gen_arg.Add(start_range);
                gen_arg.Add(end_range);
                MapReduceInfo mr_info = new MapReduceInfo((ISender)ags,
                                                          new MapReduceArgs(this.TaskName,
                                                                            mr_args.MapArg,
                                                                            gen_arg,
                                                                            mr_args.ReduceArg));
                Log("{0}: {1}, out of range, moving to the closest node to mid_range: {2} to target node, range start: {3}, range end: {4}",
                    this.TaskName, _node.Address, mid_addr, start, end);
                retval.Add(mr_info);
            }
            else
            {
                // cannot find a node in the range.
            }
            return(retval);
        }
Esempio n. 12
0
        /**
         * Generate tree within the range.
         * return list of MapReduceInfo
         */
        private List <MapReduceInfo> GenerateTreeInRange(AHAddress start, AHAddress end, List <Connection> cons, bool left, MapReduceArgs mr_args)
        {
            //Divide the range and trigger bounded broadcasting again in divided range starting with neighbor.
            //Deivided ranges are (start, n_1), (n_1, n_2), ... , (n_m, end)
            AHAddress            this_minus2 = new AHAddress(_this_addr.ToBigInteger() - 2);
            AHAddress            this_plus2  = new AHAddress(_this_addr.ToBigInteger() + 2);
            List <MapReduceInfo> retval      = new List <MapReduceInfo>();

            if (cons.Count != 0) //make sure if connection list is not empty!
            {
                //con_list is sorted.
                AHAddress last;
                if (left)
                {
                    last = end;
                }
                else
                {
                    last = start;
                }
                string rg_start, rg_end;
                //the first element of cons is the nearest.
                //Let's start with the farthest neighbor first.
                for (int i = (cons.Count - 1); i >= 0; i--)
                {
                    ArrayList  gen_arg   = new ArrayList();
                    Connection next_c    = cons[i];
                    AHAddress  next_addr = (AHAddress)next_c.Address;
                    ISender    sender    = next_c.State.Edge;
                    if (i == 0) // The last bit
                    {
                        if (left)
                        {
                            // the left nearest neighbor
                            rg_start = this_plus2.ToString();
                            rg_end   = last.ToString();
                        }
                        else
                        {
                            // the right nearest neighbor
                            rg_start = last.ToString();
                            rg_end   = this_minus2.ToString();
                        }
                    }
                    else
                    {
                        if (left) //left connections
                        {
                            rg_start = next_addr.ToString();
                            rg_end   = last.ToString();
                        }
                        else //right connections
                        {
                            rg_start = last.ToString();
                            rg_end   = next_addr.ToString();
                        }
                    }
                    gen_arg.Add(rg_start);
                    gen_arg.Add(rg_end);
                    MapReduceInfo mr_info = new MapReduceInfo(sender,
                                                              new MapReduceArgs(this.TaskName,
                                                                                mr_args.MapArg,
                                                                                gen_arg,
                                                                                mr_args.ReduceArg));
                    Log("{0}: {1}, adding address: {2} to sender list, range start: {3}, range end: {4}",
                        this.TaskName, _node.Address, next_c.Address,
                        gen_arg[0], gen_arg[1]);
                    if (left)
                    {
                        last = new AHAddress(next_addr.ToBigInteger() - 2);
                    }
                    else
                    {
                        last = new AHAddress(next_addr.ToBigInteger() + 2);
                    }
                    retval.Add(mr_info);
                }
            }
            return(retval);
        }
Esempio n. 13
0
 /** 
  * Constructor
  * @param node local node
  * @param state RPC related state.
  * @param task map-reduce task.
  * @param args arguments to the map reduce task.
  */
 public MapReduceComputation(Node node, object state, 
                             MapReduceTask task,
                             MapReduceArgs args)
 {
   _node = node;
   _rpc = node.Rpc;
   _mr_request_state = state;
   _mr_task = task;
   _mr_args = args;
   //Here is our state variable:
   _state = new State();
   _result = State.DEFAULT_OBJ;
 }
Esempio n. 14
0
 public MapReduceInfo(ISender sender, MapReduceArgs args) {
   Sender = sender;
   Args = args;
 }
Esempio n. 15
0
    /**
     * This dispatches the particular methods this class provides.
     * Currently, the only invokable method is:
     * "Start". 
     */
    public void HandleRpc(ISender caller, string method, IList args, object req_state) {
      int part_idx = method.IndexOf(':');
      if( part_idx == -1 ) {
        if (method == "Start") {
          IDictionary ht = (IDictionary) args[0];
          MapReduceArgs mr_args = new MapReduceArgs(ht);
          string task_name = mr_args.TaskName;
          MapReduceTask task;
          if (_name_to_task.TryGetValue(task_name, out task)) {
            MapReduceComputation mr = new MapReduceComputation(_node, req_state, task, mr_args);
            mr.Start();
          } 
          else {
            throw new AdrException(-32608, "No mapreduce task with name: " + task_name);          
          }
        }
        else if( method == "AddHandler" ) {
          //Make sure this is local:
          ISender tmp_call = caller;
          bool islocal = tmp_call is Node;
          while(!islocal && tmp_call is IWrappingSender) {
            tmp_call =  ((IWrappingSender)tmp_call).WrappedSender;
            islocal = tmp_call is Node;
          }
          if( !islocal ) {
            throw new AdrException(-32601, "AddHandler only valid for local callers");
          }
          SubscribeTask(new RpcMapReduceTask(_node, (IDictionary)args[0]));
          _rpc.SendResult(req_state, null);
        }
        else {
          throw new AdrException(-32601, "No Handler for method: " + method);
        }
      }
      else {
        //This is a reference to a specific part of a task:
        string part = method.Substring(0, part_idx);
        string task_name = method.Substring(part_idx + 1);
        MapReduceTask task;
        if(false == _name_to_task.TryGetValue(task_name, out task)) {
          throw new AdrException(-32608, "No mapreduce task with name: " + task_name);          
        }
        if( part == "tree" ) {
          var mra = new MapReduceArgs((IDictionary)args[0]);

          var tree_res = new Channel(1, req_state);
          tree_res.CloseEvent += this.HandleTree;
          task.GenerateTree(tree_res, mra);
        }
        else if( part == "reduce" ) {
          //Prepare the RpcResult:
          var rres_d = (IDictionary)args[2];
          ISender send = SenderFactory.CreateInstance(_node, (string)rres_d["sender"]);
          var rres = new RpcResult(send, rres_d["result"]);
          
          Channel reduce_res = new Channel(1, req_state);
          reduce_res.CloseEvent += this.HandleReduce;
          task.Reduce(reduce_res, args[0], args[1], rres);
        }
        else if( part == "map" ) {
          Channel map_res = new Channel(1, req_state);
          map_res.CloseEvent += this.HandleMap;
          task.Map(map_res, args[0]);
        }
        else {
          throw new AdrException(-32608,
              String.Format("No mapreduce task({0}) part with name: {1}", task_name, part));          
        }
      }
    }
Esempio n. 16
0
 protected void TreeHandler(object o, EventArgs eargs) {
   Channel result = (Channel)o;
   Channel q = (Channel)result.State;
   try {
     RpcResult r = (RpcResult)result.Dequeue();
     var mris = new List<MapReduceInfo>();
     foreach(IDictionary d in (IList)r.Result) {
       var uri = (string)d["sender"];
       var sender = SenderFactory.CreateInstance(_node, uri);
       var args = new MapReduceArgs((IDictionary)d["args"]);
       mris.Add(new MapReduceInfo(sender, args));
     }
     q.Enqueue(mris.ToArray());
   }
   catch(Exception x) {
     //Some kind of problem:
     q.Enqueue(x);
   }
 }
Esempio n. 17
0
    /**
     * Generates tree for bounded broadcast. Algorithm works as follows:
     * The goal is to broadcast to all nodes in range (start, end).
     * Given a range (a, b), determine all connections that belong to this range.
     * Let the left connections be l_1, l_2, ..... l_n.
     * Let the right connections be r_1, r_2, ... , r_n.
     * To left connection l_i assign the range [b_{i-1}, b_i).
     * To right connection r_i assign the range [r_i, r_{i-1}]
     * To the connection ln assign range [l_{n-1}, end)
     * To the connection rn assign range (start, r_{n-1}]
     */
    public override void GenerateTree(Channel q, MapReduceArgs mr_args)  
    {
      ArrayList gen_list = mr_args.GenArg as ArrayList;
      string start_range = gen_list[0] as string;
      AHAddress start_addr = (AHAddress) AddressParser.Parse(start_range);
      AHAddress end_addr;
      string end_range;
      /// If users do not specify an end range, this method understands 
      /// that users intend to broadcasting the whole range.
      /// Thus, the address of end range is set to (start_address - 2), 
      /// the farthest address from the start_addr.
      if (gen_list.Count < 2)  {
        BigInteger start_int = start_addr.ToBigInteger();
        BigInteger end_int = start_int -2;
        end_addr = new AHAddress(end_int);
        end_range = end_addr.ToString();
      }
      else {
        end_range = gen_list[1] as string;
        end_addr = (AHAddress) AddressParser.Parse(end_range);
      }
      Log("generating child tree, range start: {0}, range end: {1}.", start_range, end_range);
      //we are at the start node, here we go:
      ConnectionTable tab = _node.ConnectionTable;
      ConnectionList structs = tab.GetConnections(ConnectionType.Structured);
      List<MapReduceInfo> retval = new List<MapReduceInfo>();

      if (InRange(_this_addr, start_addr, end_addr)) {
        if (structs.Count > 0) {
          //make connection list in the range.
          //left connection list is a list of neighbors which are in the range (this node, end of range)
          //right connection list is a list of neighbors which are in the range (start of range, this node)
          Brunet.Collections.Pair<List<Connection>,List<Connection>> cons = GetConnectionInfo(_this_addr, start_addr, end_addr, structs);
          List<Connection> left_cons =  cons.First as List<Connection>;
          List<Connection> right_cons = cons.Second as List<Connection>;
          //PrintConnectionList(left_cons);
          //PrintConnectionList(right_cons);
          retval = GenerateTreeInRange(start_addr, end_addr, left_cons, true, mr_args);
          List<MapReduceInfo> ret_right = GenerateTreeInRange(start_addr, end_addr, right_cons, false, mr_args);
          retval.AddRange(ret_right);
        }
        else {  //this node is a leaf node.
          //MapReduceInfo mr_info = null;
          //retval.Add(mr_info);
          //Console.WriteLine("no connection in the range: return null info");
        }
      }
      else { // _node is out of range. Just pass it to the closest to the middle of range.
        retval = GenerateTreeOutRange(start_addr, end_addr, mr_args);
      }
      q.Enqueue( retval.ToArray());
    }
Esempio n. 18
0
        /**
         * Generates tree for bounded broadcast. Algorithm works as follows:
         * The goal is to broadcast to all nodes in range [local_address, end).
         * Given a range [local_address, b), determine all connections that belong to this range.
         * Let the connections be b_1, b_2, ..... b_n.
         * To connection bi assign the range [b_i, b_{i+1}).
         * To the connection bn assign range [b_n, end).]
         */
        public override void GenerateTree(Channel q, MapReduceArgs mr_args)
        {
            object gen_arg   = mr_args.GenArg;
            string end_range = gen_arg as string;

            Log("generating child tree, range end: {0}.", end_range);
            AHAddress end_addr   = (AHAddress)AddressParser.Parse(end_range);
            AHAddress start_addr = _node.Address as AHAddress;
            //we are at the start node, here we go:
            ConnectionTable tab     = _node.ConnectionTable;
            ConnectionList  structs = tab.GetConnections(ConnectionType.Structured);
            ArrayList       retval  = new ArrayList();

            if (structs.Count > 0)
            {
                Connection curr_con = structs.GetLeftNeighborOf(_node.Address);
                int        curr_idx = structs.IndexOf(curr_con.Address);
                //keep going until we leave the range
                int       count    = 0;
                ArrayList con_list = new ArrayList();
                while (count++ < structs.Count && ((AHAddress)curr_con.Address).IsBetweenFromLeft(start_addr, end_addr))
                {
                    con_list.Add(curr_con);
                    //Log("adding connection: {0} to list.", curr_con.Address);
                    curr_idx = (curr_idx + 1) % structs.Count;
                    curr_con = structs[curr_idx];
                }

                Log("{0}: {1}, number of child connections: {2}",
                    this.TaskName, _node.Address, con_list.Count);
                for (int i = 0; i < con_list.Count; i++)
                {
                    MapReduceInfo mr_info = null;
                    ISender       sender  = null;
                    Connection    con     = (Connection)con_list[i];
                    sender = (ISender)con.Edge;
                    //check if last connection
                    if (i == con_list.Count - 1)
                    {
                        mr_info = new MapReduceInfo((ISender)sender,
                                                    new MapReduceArgs(this.TaskName,
                                                                      mr_args.MapArg,   //map argument
                                                                      end_range,        //generate argument
                                                                      mr_args.ReduceArg //reduce argument
                                                                      ));

                        Log("{0}: {1}, adding address: {2} to sender list, range end: {3}",
                            this.TaskName, _node.Address,
                            con.Address, end_range);
                        retval.Add(mr_info);
                    }
                    else
                    {
                        string child_end = ((Connection)con_list[i + 1]).Address.ToString();
                        mr_info = new MapReduceInfo(sender,
                                                    new MapReduceArgs(this.TaskName,
                                                                      mr_args.MapArg,
                                                                      child_end,
                                                                      mr_args.ReduceArg));
                        Log("{0}: {1}, adding address: {2} to sender list, range end: {3}",
                            this.TaskName, _node.Address,
                            con.Address, child_end);
                        retval.Add(mr_info);
                    }
                }
            }
            q.Enqueue(retval.ToArray(typeof(MapReduceInfo)));
        }
Esempio n. 19
0
 /**
  * When a node is out of the range, this method is called.
  * This method tries to find the nearest node to the middle of range using greedty algorithm.
  * return list of MapReduceInfo
  */
 private List<MapReduceInfo> GenerateTreeOutRange(AHAddress start, AHAddress end, MapReduceArgs mr_args) {
   List<MapReduceInfo> retval = new List<MapReduceInfo>();
   BigInteger up = start.ToBigInteger();
   BigInteger down = end.ToBigInteger();
   BigInteger mid_range = (up + down) /2;
   if (mid_range % 2 == 1) {mid_range = mid_range -1; }
   AHAddress mid_addr = new AHAddress(mid_range);
   //if (!mid_addr.IsBetweenFromLeft(start, end) ) {
   if (!InRange(mid_addr, start, end) ) {
     mid_range += Address.Half;
     mid_addr = new AHAddress(mid_range);
   }
   ArrayList gen_arg = new ArrayList();
   if (NextGreedyClosest(mid_addr) != null ) {
     AHGreedySender ags = new AHGreedySender(_node, mid_addr);
     string start_range = start.ToString();
     string end_range = end.ToString();
     gen_arg.Add(start_range);
     gen_arg.Add(end_range);
     MapReduceInfo mr_info = new MapReduceInfo( (ISender) ags,
     			                new MapReduceArgs(this.TaskName,
     						          mr_args.MapArg,
     							  gen_arg,
                                                               mr_args.ReduceArg));
     Log("{0}: {1}, out of range, moving to the closest node to mid_range: {2} to target node, range start: {3}, range end: {4}",
     		  this.TaskName, _node.Address, mid_addr, start, end);
     retval.Add(mr_info);
   }
   else  {
     // cannot find a node in the range. 
   }
   return retval;
 }
Esempio n. 20
0
 /** tree generator function.
  * @param q The channel into which to put exactly one IList<MapReduceInfo>
  * @param args the MapReduceArgs for this call
  */
 public virtual void GenerateTree(Channel q, MapReduceArgs args)
 {
     throw new NotImplementedException();
 }
Esempio n. 21
0
    /**
     * Generates tree for bounded broadcast. Algorithm works as follows:
     * The goal is to broadcast to all nodes in range [local_address, end).
     * Given a range [local_address, b), determine all connections that belong to this range.
     * Let the connections be b_1, b_2, ..... b_n.
     * To connection bi assign the range [b_i, b_{i+1}).
     * To the connection bn assign range [b_n, end).]
     */
    public override void GenerateTree(Channel q, MapReduceArgs mr_args) 
    {
      object gen_arg = mr_args.GenArg;
      string end_range = gen_arg as string;
      Log("generating child tree, range end: {0}.", end_range);
      AHAddress end_addr = (AHAddress) AddressParser.Parse(end_range);
      AHAddress start_addr = _node.Address as AHAddress;
      //we are at the start node, here we go:
      ConnectionTable tab = _node.ConnectionTable;
      ConnectionList structs = tab.GetConnections(ConnectionType.Structured);
      ArrayList retval = new ArrayList();

      if (structs.Count > 0) {
        Connection curr_con = structs.GetLeftNeighborOf(_node.Address);
        int curr_idx = structs.IndexOf(curr_con.Address);
        //keep going until we leave the range
        int count = 0;
        List<Connection> con_list = new List<Connection>();
        //ArrayList con_list = new ArrayList();
        while (count++ < structs.Count && ((AHAddress) curr_con.Address).IsBetweenFromLeft(start_addr, end_addr)) {
          con_list.Add(curr_con);
          //Log("adding connection: {0} to list.", curr_con.Address);
          curr_idx  = (curr_idx + 1)%structs.Count;
          curr_con = structs[curr_idx];
        }
        
        Log("{0}: {1}, number of child connections: {2}", 
            this.TaskName, _node.Address, con_list.Count);
        for (int i = 0; i < con_list.Count; i++) {
          MapReduceInfo mr_info = null;
          ISender sender = null;
          Connection con = (Connection) con_list[i];
          sender = con.State.Edge;
          //check if last connection
          if (i == con_list.Count - 1) {
            mr_info = new MapReduceInfo( (ISender) sender, 
                                         new MapReduceArgs(this.TaskName, 
                                                           mr_args.MapArg, //map argument
                                                           end_range, //generate argument
                                                           mr_args.ReduceArg //reduce argument
                                                           ));
            
            Log("{0}: {1}, adding address: {2} to sender list, range end: {3}", 
                this.TaskName, _node.Address, 
                con.Address, end_range);
            retval.Add(mr_info);
          }
          else {
            string child_end = ((Connection) con_list[i+1]).Address.ToString();
            mr_info = new MapReduceInfo( sender,
                                         new MapReduceArgs(this.TaskName,
                                                           mr_args.MapArg, 
                                                           child_end,
                                                           mr_args.ReduceArg));
            Log("{0}: {1}, adding address: {2} to sender list, range end: {3}", 
                this.TaskName, _node.Address, 
                con.Address, child_end);
            retval.Add(mr_info);
          }
        }
      }
      q.Enqueue( retval.ToArray(typeof(MapReduceInfo)));
    }
Esempio n. 22
0
 /** tree generator function.
  * @param q The channel into which to put exactly one IList<MapReduceInfo>
  * @param args the MapReduceArgs for this call
  */
 public virtual void GenerateTree(Channel q, MapReduceArgs args) {
   throw new NotImplementedException();
 }