write phase one-Invalidation request
This commit is contained in:
parent
e10f04ca25
commit
013f08e7e3
|
@ -330,6 +330,59 @@ public class memSession implements Runnable
|
|||
}
|
||||
}
|
||||
break;
|
||||
case nr_write:
|
||||
{
|
||||
nr_write msgLite = msg.getMessageLite();
|
||||
Integer state = getLockState(msgLite.getKey());
|
||||
if (state == LockKey.waitLock)
|
||||
{
|
||||
addSession(e);
|
||||
return ;
|
||||
}
|
||||
else if (state == LockKey.badLock)
|
||||
{
|
||||
removeLock(msgLite.getKey());
|
||||
}
|
||||
|
||||
nm_write_1.Builder builder = nm_write_1.newBuilder();
|
||||
builder.setKey(msgLite.getKey());
|
||||
builder.setValue(msgLite.getValue());
|
||||
builder.setMemID(ClientMgr.getInstance().mClientNumber);
|
||||
builder.setTime(msgLite.getTime());
|
||||
|
||||
NetMsg send = NetMsg.newMessage();
|
||||
send.setMessageLite(builder);
|
||||
send.setMsgID(EMSGID.nm_write_1);
|
||||
int count = sendOtherAllCopyMsg(gethashMem(msgLite.getKey()), send);
|
||||
|
||||
if (count>0)
|
||||
{
|
||||
LockKey lockKey = new LockKey(ClientMgr.getInstance().mClientNumber, count, System.currentTimeMillis(), LockKey.waitLock);
|
||||
if(lockKey(msgLite.getKey(), lockKey) == false)
|
||||
{
|
||||
System.out.println("nr_write lock fail");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean res = client.set(msgLite.getKey(), msgLite.getValue());
|
||||
if(res == false)
|
||||
{
|
||||
System.err.println("write_2 fail");
|
||||
}
|
||||
nr_Read_res.Builder builder2 = nr_Read_res.newBuilder();
|
||||
builder2.setKey(msgLite.getKey());
|
||||
builder2.setValue(msgLite.getValue());
|
||||
builder2.setTime(msgLite.getTime());
|
||||
|
||||
NetMsg send2 = NetMsg.newMessage();
|
||||
send2.setMessageLite(builder);
|
||||
send2.setMsgID(EMSGID.nr_write_res);
|
||||
webServeChannel.write(send2);
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
System.err.println(msg.getMsgID().toString());
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue