def put(self, data): ''' ''' # TODO request = replicator_pb2.Request(key="hello",value="1000",op =replicator_pb2._REQUEST_OPERATION.values_by_number[0].name ) self.stub.performOperation(request)
def send(self, cmd, arg): response = self.stub.send( replicator_pb2.Request(cmd=cmd, argument=arg, merkleRootHash='TODO', cmdHash='TODO')) return response.result
def sync(self): syncro = self.stub.synchronizer(replicator_pb2.Request(data="start")) for s in syncro: if s.operation == "put": print("Operation Performed : " + s.operation + " " + s.key + " " + s.data) self.db.put(s.key.encode(), s.data.encode()) elif s.operation == "delete": print("Operation Performed : " + s.operation + " " + s.key) self.db.put(s.key.encode(), s.data.encode())
def get_updates(self): """Get updates from master""" responses = self.stub.update_slave( replicator_pb2.Request(data="Send me data!")) for resp in responses: print(resp) if resp.method_type == "put": SlaveUpdater.debug = SlaveUpdater.debug + 1 logging.debug( str(SlaveUpdater.debug) + "," + "put" + "," + resp.key + "," + (resp.value).strip("\n")) self.put(resp.key, resp.value) elif resp.method_type == "delete": SlaveUpdater.debug = SlaveUpdater.debug + 1 logging.debug( str(SlaveUpdater.debug) + "," + "delete" + "," + resp.key + "," + "") self.delete(resp.key) else: print("Nothing to do")
def delete(self, key): """Delte from Slave DB""" return self.stub.delete(replicator_pb2.Request(data=key))
def put(self, value): """Put in Slave DB""" return self.stub.put(replicator_pb2.Request(data=value))
def get(self, key): """Put in Slave DB""" return self.stub.get(replicator_pb2.Request(data=key))
def delete(self, key): return self.stub.delete(replicator_pb2.Request(key=key))
def put(self, key, value): return self.stub.put(replicator_pb2.Request(key=key, value=value))
def remove(self, k): request = replicator_pb2.Request(key=k,value="0",op =replicator_pb2._REQUEST_OPERATION.values_by_number[1].name ) self.stub.performOperation(request)
def put(self, k , v): request = replicator_pb2.Request(key=k,value=v,op =replicator_pb2._REQUEST_OPERATION.values_by_number[0].name ) self.stub.performOperation(request)
def put(self, key, data): return self.stub.put(replicator_pb2.Request(key=key, data=data))
def GetInstance(self, request): return self.stub.GetInstance(replicator_pb2.Request(data=request))