Beispiel #1
0
def do_paxos_broad(request):

    param = json.loads(request.body)
    item = str(param.get('item'))
    if not str_equal(item ,key_paxos_leader):
        print 'get broad msg ITEM %s VALUE %s BROADUUID %s' % (item,param.get('val'),param.get('broadUuid'))
        print 'get broad msg PARAM %s' % (str(param))
    broadUuid = param.get('broadUuid')
    if not broadUuid:
        return jresponse('-1','broadUuid error',request,200)

    if str_equal(item ,key_paxos_leader):
        
        leaderUuid = param.get('val')
        leaderTime = time.time()
        if broadUuid == wsgiObj.broadUuid:
            pass
        else:
            val = (leaderUuid,leaderTime,broadUuid)
            wsgiObj.PAXOS_QUEUE.put((item,val))
            acceptor_broadcast(item, leaderUuid, broadUuid)
    else:
        val = param.get('val')
        if broadUuid == wsgiObj.itemBroadUuid.get(item,''):
            pass
        else:
            print 'acceptor recv ITEM %s VALUE %s BROADUUID %s' % (item,val,broadUuid)
            wsgiObj.itemBroadUuid.put(item,broadUuid)
            wsgiObj.PAXOS_VALUE.put(item,val)
            acceptor_broadcast(item, val, broadUuid)
            
    return jresponse('0','',request,200)
Beispiel #2
0
def do_mkey_store(request):
	
	if not is_leader():
		return jresponse('-1',ERR_NOT_LEADER,request,200)
	
	param = json.loads(request.body)
	logentry = param.get('logentry')
	print 'leader key store ',logentry
	log_store(logentry)
	return jresponse('0','',request,200)
Beispiel #3
0
def process_request(request):
    
    url = request.path
    if url not in url2view:
        return jresponse('-1','url error',request,404)
     
    return url2view[url](request)
Beispiel #4
0
def process_request(request):

    url = request.path
    if url not in url2view:
        return jresponse('-1', 'url error', request, 404)

    return url2view[url](request)
Beispiel #5
0
def doKeySet(request):

    param = json.loads(request.body)
    key = param.get('key')
    val = param.get('val')
    print 'mst do key set'
    flag, msg = logstorage('set', key, val)
    print 'mst log store ', msg
    if not flag:
        if msg == ERR_NOT_LEADER:
            print ERR_NOT_LEADER
            sys.exit(0)
        else:
            return jresponse('-1', msg, request, 200)

    machine_key_set(key, val)

    return jresponse('0', '', request, 200)
Beispiel #6
0
def do_paxos_learn(request):

    param = json.loads(request.body)
    item = str(param.get('item'))
    if str_equal(item ,key_paxos_leader):
        leaderUuid,leaderTime,broadUuid = wsgiObj.PAXOS_VALUE.get(key_paxos_leader, wsgiObj.paxos_leader_default)
        if not leaderUuid:
            msgval = json.dumps(wsgiObj.paxos_leader_default)
        else:
            leaderTerm = wsgiObj.PAXOS_LEADER_TERM - (time.time()-leaderTime)
            msgval = json.dumps((leaderUuid,leaderTerm,broadUuid))
    else:
        msgval = wsgiObj.PAXOS_VALUE.get(item,'')
        print 'openmsg ITEM %s VALUE %s' % (item,msgval)
    return jresponse('0',msgval,request,200)
Beispiel #7
0
def doTest(request):

	return jresponse('0','test ok',request,200)
Beispiel #8
0
def do_paxos_alive(request):
	
	param = json.loads(request.body)
	clientUuid = param.get('clientUuid')
	return jresponse('0',wsgiObj.hostUuid,request,200)
Beispiel #9
0
def doMstGet(request):

    mst = machine_all()
    return jresponse('0', json.dumps(mst), request, 200)
Beispiel #10
0
def doKeyDel(request):

    return jresponse('0', 'test ok', request, 200)