def vector_converge(tea_name,r_rating, r_vc): if DEBUG: print "[new recieved]tea_name:" , tea_name, "rating:", r_rating, "new v clocks:",r_vc rating, choices, vc = get_from_redis(tea_name) if rating == None: # no key found for the tea conv_rating = r_rating conv_choices = [r_rating] conv_vc = r_vc else: if DEBUG: print "[previous]tea_name:" , tea_name, "rating:", rating,"choices:", choices, "new v clocks:",vc #compare existing clocks and received clock #print "r_vc = " , r_vc.clock , "vc=", vc.clock , if DEBUG: print "[compare] r_vc == vc :", (r_vc == vc) print "[compare] r_vc > vc: " , (r_vc > vc) print "[compare] r_vc < vc: " , (r_vc < vc) print "[compare] r_vc >= vc: " ,( r_vc >= vc) print "[compare] coalesce = " , VectorClock.coalesce([r_vc,vc]) print "[compare] converge = " , VectorClock.converge([r_vc,vc]) if r_vc == vc: conv_rating = r_rating conv_choices = None conv_vc = None elif r_vc > vc: # more recent data #compute mean value conv_rating = r_rating #choose the recent vector clocks conv_vc = r_vc #choose the recent choices based on the clocks conv_choices = [r_rating] elif r_vc < vc: # ignore if DEBUG: print "[ignore] r_vc<vc" #compute mean value conv_rating = rating #choose the recent vector clocks conv_vc = None #choose the recent choices based on the clocks conv_choices = None else: combined_clocks_list = VectorClock.coalesce([r_vc,vc]) if DEBUG: print "combined clocks:",combined_clocks_list if r_vc in combined_clocks_list and vc in combined_clocks_list: combined_clocks_list.sort() #choose merged choices based on the clocks conv_choices = choices + [r_rating] conv_rating = meanAvg(conv_choices) #choose the recent vector clocks conv_vc = VectorClock.converge([r_vc,vc]) if DEBUG: print "[incom] c_choices=", conv_choices, "c_rating=",conv_rating, "c_vc=", conv_vc return conv_rating, conv_choices,conv_vc
def put(self, key, metadata, value, destnode=None): # print "node: ",len(DynamoNode.nodelist) #modified temp = metadata while True: ################################### metadata = temp if destnode is None: # Pick a random node to send the request to destnode = random.choice(DynamoNode.nodelist) # Input metadata is always a sequence, but we always need to insert a # single VectorClock object into the ClientPut message # print '-------------------------choice:', destnode if len(metadata) == 1 and metadata[0] is None: metadata = VectorClock() else: # A Put operation always implies convergence metadata = VectorClock.converge(metadata) putmsg = ClientPut(self.addr, destnode, key, value, metadata) #modified con = self.connections[self.servers.index(destnode)] result = Framework.send_message(putmsg, con) if result is not False: break destnode = None ################################## return result
def put_message(self, fromnode, key, value, metadata): #print 'client put!!!' metadata = pickle.loads(metadata) if metadata is None: metadata = VectorClock() else: # A Put operation always implies convergence metadata = VectorClock.converge(metadata) putmsg = ClientPut(fromnode, self.addr, key, value, metadata) self.rcv_clientput(putmsg)
def put(self, key, metadata, value, destnode=None): if destnode is None: destnode = random.choice(DynamoNode.nodelist) if len(metadata) == 1 and metadata[0] is None: metadata = VectorClock() else: metadata = VectorClock.converge(metadata) putmsg = ClientPut(self, destnode, key, value, metadata) Framework.send_message(putmsg) return putmsg
def put_message(self, fromnode, key, value, metadata): #print 'client put!!!' metadata = pickle.loads(metadata) if metadata is None: metadata = VectorClock() else: # A Put operation always implies convergence metadata = VectorClock.converge(metadata) putmsg = ClientPut(fromnode, self.addr, key, value, metadata) Framework.send_message(putmsg) # Framework.schedule(timers_to_process=0) Framework.schedule()
def put(self, key, metadata, value, destnode=None): if destnode is None: # Pick a random node to send the request to destnode = random.choice(DynamoNode.nodelist) # Input metadata is always a sequence, but we always need to insert a # single VectorClock object into the ClientPut message if len(metadata) == 1 and metadata[0] is None: metadata = VectorClock() else: # A Put operation always implies convergence metadata = VectorClock.converge(metadata) putmsg = ClientPut(self, destnode, key, value, metadata) Framework.send_message(putmsg) return putmsg
def vector_converge(tea_name,r_rating, r_vc): conv_list =[] if DEBUG: print "\n[new recieved]tea_name:" , tea_name, "rating:", r_rating, "new v clocks:",r_vc rating, choices, vc_list = get_from_redis(tea_name) if rating == None: # no key found for the tea conv_rating = r_rating conv_choices = [r_rating] conv_list.append(r_vc) else: vc = merge_dict(vc_list) coal = VectorClock.coalesce([vc,r_vc]) conv = VectorClock.converge([vc,r_vc]) if DEBUG: print "[previous]vc_list to vc format:", vc print "[previous]tea_name:" , tea_name, "rating:", rating,"choices:", choices print "[compare] r_vc == vc :", (r_vc == vc) print "[compare] r_vc > vc: " , (r_vc > vc) print "[compare] r_vc < vc: " , (r_vc < vc) print "[compare] r_vc >= vc: " ,( r_vc >= vc) print "[compare] coalesce = " , VectorClock.coalesce([vc,r_vc]) print "[compare] converge = " , VectorClock.converge([vc,r_vc]) print "[compare] r_vc in v.coalesce = ",r_vc in VectorClock.coalesce([vc,r_vc]) print "[compare] vc in v.coalesce = ",vc in VectorClock.coalesce([vc,r_vc]) print "[compare] r_vc in v.converge = ",r_vc in seperate_to_vc_list(conv) print "[compare] vc in v.converge = ",vc in seperate_to_vc_list(conv) print "[compare] r_vc < v.converge ", r_vc <= VectorClock.converge([vc,r_vc]) print "[compare] vc < v.converge ", vc <= VectorClock.converge([vc,r_vc]) is_incomparable = (r_vc in coal) and (vc in coal) and ( r_vc <= conv ) and ( vc <= conv) if r_vc == vc: conv_rating = r_rating conv_choices = None conv_list = None elif r_vc > vc: # more recent data #compute mean value,recent vector clocksd, and choices conv_rating = r_rating conv_choices = [r_rating] conv_list.append(r_vc) elif r_vc < vc: # ignore if DEBUG: print "[ignore] r_vc<vc" conv_rating = rating conv_choices = None conv_list = None elif is_incomparable: combined_clocks_list = VectorClock.coalesce([vc,r_vc]) if DEBUG: print "combined clocks:",combined_clocks_list print "----- [incom] r_vc:", r_vc print "----- [incom] vc:", vc print "----- [incom] coal:", coal print "----- [incom] conv:", conv print "----- [incom] choices:",choices, ",r_choices:", r_rating conv_vc_list = seperate_to_vc_list(conv) #find choices related with conv_list conv_choices = [] conv_list=[] conv_list,conv_choices = decide_to_append_vc_list(vc_list,choices,conv_vc_list,conv_list,conv_choices) #check previous vc list conv_list,conv_choices = decide_to_append_vc_list([r_vc],[r_rating],conv_vc_list,conv_list,conv_choices)#check received r_vc list conv_list,conv_choices = eliminate_old_clocks(conv_list,conv_choices) #double check conv_rating = meanAvg(conv_choices) if DEBUG: print "----- [incomp] new conv_choices:",conv_choices print "----- [incomp] new conv_list:", conv_list print "----- [incomp] new conv_rating:",conv_rating return conv_rating, conv_choices,conv_list