def client_req_executed(client_req: ClientRequest, state_length, pend_length): """Called whenever a client request is fully executed, i.e. committed The total execution time is calculated and emitted to the gauge tracking the client request execution time. """ if client_req not in client_reqs: logger.debug(f"ClientRequest {client_req} not tracked") return exec_time = time.time() - client_reqs[client_req][START_TIME] logger.info(f"req execed in {exec_time} s") avg_pend_length = (pend_length + client_reqs[client_req][PEND]) / 2 # emit execution time for this client_req client_req_exec_time.labels(client_req.get_client_id(), client_req.get_timestamp(), state_length, avg_pend_length).set(exec_time) # stop tracking client_req del client_reqs[client_req]
def handle_client_message(): """Route for clients to send messages to a node.""" data = request.get_json() if not ("operation" in data and "client_id" in data and "timestamp" in data and "type" in data["operation"] and "args" in data["operation"]): return abort(400) try: op = Operation(data["operation"]["type"], data["operation"]["args"]) req = ClientRequest(data["client_id"], data["timestamp"], op) pend_reqs = app.resolver.inject_client_req(req) logger.debug(f"Injected req {req} to pend_reqs") return jsonify({"pend_reqs": jsonpickle.encode(pend_reqs)}) except Exception as e: logger.error(f"Error when injecting client request through API: {e}") return abort(500)
from .abstract_integration_test import AbstractIntegrationTest from modules.replication.models.replica_structure import ReplicaStructure from modules.replication.models.client_request import ClientRequest from modules.replication.models.request import Request from modules.replication.models.operation import Operation from modules.enums import ReplicationEnums as re from modules.constants import REQUEST, X_SET # globals F = 1 N = 6 logger = logging.getLogger(__name__) start_state = {} req1 = Request((ClientRequest(0, 189276398, Operation( "APPEND", 1 ))), 0, 1) req2 = Request((ClientRequest(0, 189276399, Operation( "APPEND", 2 ))), 0, 2) req3 = Request((ClientRequest(0, 189276402, Operation( "APPEND", 3 ))), 0, 3) for i in range(N): start_state[str(i)] = { "REPLICATION_MODULE": { "rep": [ ReplicaStructure(0, rep_state=[1],r_log=[{REQUEST: req1, X_SET:{0,2,3,5}}], prim=0),
from . import helpers from .abstract_integration_test import AbstractIntegrationTest from modules.replication.models.replica_structure import ReplicaStructure from modules.replication.models.client_request import ClientRequest from modules.replication.models.request import Request from modules.replication.models.operation import Operation from modules.constants import REQUEST, STATUS, MAXINT, SIGMA, X_SET, REPLY from modules.enums import ReplicationEnums as enums # globals F = 1 N = 6 logger = logging.getLogger(__name__) start_state = {} client_req_1 = ClientRequest(0, 0, Operation("APPEND", 1)) client_req_2 = ClientRequest(0, 1, Operation("APPEND", 2)) client_req_3 = ClientRequest(0, 3, Operation("APPEND", 3)) req_1 = Request(client_req_1, 0, 1) for i in range(N): start_state[str(i)] = { "REPLICATION_MODULE": { "rep": [ ReplicaStructure(j, rep_state=[1], r_log=[{ REQUEST: req_1, X_SET: {0, 1, 2, 3, 4, 5} }], pend_reqs=[client_req_2, client_req_3],
from . import helpers from .abstract_integration_test import AbstractIntegrationTest from modules.replication.models.replica_structure import ReplicaStructure from modules.replication.models.client_request import ClientRequest from modules.replication.models.request import Request from modules.replication.models.operation import Operation from modules.constants import REQUEST, STATUS, MAXINT, SIGMA, X_SET, REPLY from modules.enums import ReplicationEnums as enums # globals F = 1 N = 6 logger = logging.getLogger(__name__) start_state = {} client_req_1 = ClientRequest(0, 189276398, Operation("APPEND", 1)) client_req_2 = ClientRequest(0, 189276400, Operation("APPEND", 2)) client_req_3 = ClientRequest(0, 189276450, Operation("APPEND", 3)) req_1 = Request(client_req_1, 0, 1) req_2 = Request(client_req_1, 0, 1) for i in range(N): start_state[str(i)] = { "REPLICATION_MODULE": { "rep": [ ReplicaStructure(j, rep_state=[1], r_log=[{ REQUEST: req_1, X_SET: {0, 1, 2, 3, 4, 5} }],
for i in range(N): start_state[str(i)] = { "VIEW_ESTABLISHMENT_MODULE": { "views": views, "phs": phases, "vChange": vChanges, "witnesses": witnesses }, "REPLICATION_MODULE": { "rep": [ ReplicaStructure( j, number_of_clients=2, pend_reqs=[ ClientRequest(0, i, Operation("APPEND", i)) for i in range(10) ], ) for j in range(N) ] } } args = {"BYZANTINE": {"NODES": [0], "BEHAVIOR": "UNRESPONSIVE_TO_HALF"}} target_rep = [i for i in range(10)] class TestByzNodeSendingDifferentViews(AbstractIntegrationTest): """Checks that a Byzantine primary being unresponsive to some is detected.""" async def bootstrap(self):
from . import helpers from .abstract_integration_test import AbstractIntegrationTest from modules.replication.models.replica_structure import ReplicaStructure from modules.replication.models.client_request import ClientRequest from modules.replication.models.request import Request from modules.replication.models.operation import Operation from modules.constants import REQUEST, STATUS, MAXINT, SIGMA, X_SET, REPLY from modules.enums import ReplicationEnums as enums # globals F = 1 N = 6 logger = logging.getLogger(__name__) start_state = {} client_req_1 = ClientRequest(0, 0, Operation("APPEND", 1)) for i in range(N): start_state[str(i)] = { # force stable view_pair for all nodes "VIEW_ESTABLISHMENT_MODULE": { "views": [{"current": 0, "next": 0} for i in range(N)] }, "REPLICATION_MODULE": { "rep": [ ReplicaStructure( j, pend_reqs=[client_req_1], prim = 0 ) for j in range(N) ]
# local from . import helpers from .abstract_integration_test import AbstractIntegrationTest from modules.replication.models.replica_structure import ReplicaStructure from modules.replication.models.client_request import ClientRequest from modules.replication.models.request import Request from modules.replication.models.operation import Operation from modules.constants import REPLY, REQUEST # globals F = 1 N = 6 logger = logging.getLogger(__name__) start_state = {} req = ClientRequest(0, 189276398, Operation("APPEND", 1)) for i in range(N): start_state[str(i)] = { # force stable view_pair for all nodes "VIEW_ESTABLISHMENT_MODULE": { "views": [{ "current": 0, "next": 0 } for i in range(N)] }, "REPLICATION_MODULE": { "rep": [ReplicaStructure(j, pend_reqs=[req], prim=0) for j in range(N)] } }
from . import helpers from .abstract_integration_test import AbstractIntegrationTest from modules.replication.models.replica_structure import ReplicaStructure from modules.replication.models.client_request import ClientRequest from modules.replication.models.request import Request from modules.replication.models.operation import Operation from modules.constants import REQUEST, STATUS, MAXINT, SIGMA, X_SET, REPLY from modules.enums import ReplicationEnums as enums # globals F = 1 N = 6 logger = logging.getLogger(__name__) start_state = {} client_reqs = [ClientRequest(0, i, Operation("APPEND", i)) for i in range(20)] reqs = [Request(client_reqs[i], 0, i) for i in range(20)] r_logs = [{REQUEST: reqs[i], X_SET: {0, 1, 2, 3, 4}} for i in range(20)] for i in range(N): start_state[str(i)] = { "REPLICATION_MODULE": { "rep": [ ReplicaStructure(j, rep_state=[k for k in range(20)], r_log=r_logs[-15:], pend_reqs=[]) for j in range(N - 1) ] + [ ReplicaStructure( 5, rep_state=[0], r_log=[r_logs[0]], pend_reqs=[]) ]
from . import helpers from .abstract_integration_test import AbstractIntegrationTest from modules.replication.models.replica_structure import ReplicaStructure from modules.replication.models.client_request import ClientRequest from modules.replication.models.request import Request from modules.replication.models.operation import Operation from modules.enums import ReplicationEnums as re from modules.constants import REQUEST, X_SET # globals F = 1 N = 6 logger = logging.getLogger(__name__) start_state = {} client_req1 = ClientRequest(0, 189276398, Operation("APPEND", 1)) client_req3 = ClientRequest(0, 189276402, Operation("APPEND", 3)) client_req2 = ClientRequest(0, 189276399, Operation("APPEND", 2)) req1 = Request(client_req1, 0, 0) req2 = Request(client_req2, 0, 1) req3 = Request(client_req3, 0, 2) for i in range(N): start_state[str(i)] = { # force stable view_pair for all nodes "VIEW_ESTABLISHMENT_MODULE": { "views": [{ "current": 0, "next": 0 } for i in range(N)]