workload.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. from psycopg import Cursor
  10. from materialize.scalability.endpoint.endpoint import Endpoint
  11. from materialize.scalability.operation.operation_data import OperationData
  12. from materialize.scalability.operation.scalability_operation import Operation
  13. from materialize.scalability.schema.schema import Schema
  14. from materialize.scalability.workload.workload_version import WorkloadVersion
  15. class Workload:
  16. def init_operations(self) -> list[Operation]:
  17. return []
  18. def operations(self) -> list[Operation]:
  19. raise NotImplementedError
  20. def execute_operation(
  21. self,
  22. operation: Operation,
  23. cursor: Cursor,
  24. worker_id: int,
  25. transaction_index: int,
  26. verbose: bool,
  27. ) -> None:
  28. data = OperationData(cursor, worker_id)
  29. self.amend_data_before_execution(data)
  30. if verbose:
  31. print(f"#{transaction_index}: {operation} (worker_id={worker_id})")
  32. operation.execute(data)
  33. def amend_data_before_execution(self, data: OperationData) -> None:
  34. pass
  35. def name(self) -> str:
  36. return self.__class__.__name__
  37. def version(self) -> WorkloadVersion:
  38. return WorkloadVersion.create(1, 0, 0)
  39. class WorkloadWithContext(Workload):
  40. endpoint: Endpoint
  41. schema: Schema
  42. def set_endpoint(self, endpoint: Endpoint) -> None:
  43. self.endpoint = endpoint
  44. def set_schema(self, schema: Schema) -> None:
  45. self.schema = schema