2021-06-17 11:49:57 +08:00
|
|
|
from enum import Enum
|
2021-06-24 11:56:08 +08:00
|
|
|
from random import randint
|
2021-12-07 21:45:26 +08:00
|
|
|
import time
|
2022-06-30 09:00:18 +08:00
|
|
|
from datetime import datetime
|
|
|
|
import functools
|
2021-06-04 10:33:34 +08:00
|
|
|
from time import sleep
|
2021-06-17 11:49:57 +08:00
|
|
|
from base.collection_wrapper import ApiCollectionWrapper
|
2022-05-15 20:41:59 +08:00
|
|
|
from base.utility_wrapper import ApiUtilityWrapper
|
2021-06-04 10:33:34 +08:00
|
|
|
from common import common_func as cf
|
|
|
|
from common import common_type as ct
|
2021-11-08 21:41:09 +08:00
|
|
|
from chaos import constants
|
2021-08-18 16:06:10 +08:00
|
|
|
|
|
|
|
from common.common_type import CheckTasks
|
2021-06-24 11:56:08 +08:00
|
|
|
from utils.util_log import test_log as log
|
2022-06-30 09:00:18 +08:00
|
|
|
from utils.api_request import Error
|
2021-06-04 10:33:34 +08:00
|
|
|
|
2021-06-17 11:49:57 +08:00
|
|
|
|
|
|
|
class Op(Enum):
|
2022-06-30 09:00:18 +08:00
|
|
|
create = 'create'
|
|
|
|
insert = 'insert'
|
|
|
|
flush = 'flush'
|
|
|
|
index = 'index'
|
|
|
|
search = 'search'
|
|
|
|
query = 'query'
|
|
|
|
delete = 'delete'
|
|
|
|
compact = 'compact'
|
|
|
|
drop = 'drop'
|
|
|
|
load_balance = 'load_balance'
|
|
|
|
bulk_load = 'bulk_load'
|
|
|
|
unknown = 'unknown'
|
|
|
|
|
|
|
|
|
|
|
|
timeout = 40
|
2021-12-01 18:07:31 +08:00
|
|
|
enable_traceback = False
|
2022-06-30 09:00:18 +08:00
|
|
|
DEFAULT_FMT = '[start time:{start_time}][time cost:{elapsed:0.8f}s][operation_name:{operation_name}][collection name:{collection_name}] -> {result!r}'
|
|
|
|
|
|
|
|
|
|
|
|
def trace(fmt=DEFAULT_FMT, prefix='chaos-test', flag=True):
|
|
|
|
def decorate(func):
|
|
|
|
@functools.wraps(func)
|
|
|
|
def inner_wrapper(self, *args, **kwargs):
|
|
|
|
start_time = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
|
|
|
|
t0 = time.perf_counter()
|
|
|
|
res, result = func(self, *args, **kwargs)
|
|
|
|
elapsed = time.perf_counter() - t0
|
|
|
|
end_time = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
|
|
|
|
if flag:
|
|
|
|
collection_name = self.c_wrap.name
|
|
|
|
operation_name = func.__name__
|
|
|
|
log_str = f"[{prefix}]" + fmt.format(**locals())
|
|
|
|
# TODO: add report function in this place, like uploading to influxdb
|
|
|
|
# it is better a async way to do this, in case of blocking the request processing
|
|
|
|
log.debug(log_str)
|
|
|
|
if result:
|
|
|
|
self.rsp_times.append(elapsed)
|
|
|
|
self.average_time = (
|
|
|
|
elapsed + self.average_time * self._succ) / (self._succ + 1)
|
|
|
|
self._succ += 1
|
|
|
|
else:
|
|
|
|
self._fail += 1
|
|
|
|
return res, result
|
|
|
|
return inner_wrapper
|
|
|
|
return decorate
|
|
|
|
|
|
|
|
|
|
|
|
def exception_handler():
|
|
|
|
def wrapper(func):
|
|
|
|
@functools.wraps(func)
|
|
|
|
def inner_wrapper(self, *args, **kwargs):
|
|
|
|
try:
|
|
|
|
res, result = func(self, *args, **kwargs)
|
|
|
|
return res, result
|
|
|
|
except Exception as e:
|
|
|
|
log_row_length = 300
|
|
|
|
e_str = str(e)
|
|
|
|
log_e = e_str[0:log_row_length] + \
|
|
|
|
'......' if len(e_str) > log_row_length else e_str
|
|
|
|
log.error(log_e)
|
|
|
|
return Error(e), False
|
|
|
|
return inner_wrapper
|
|
|
|
return wrapper
|
2021-07-03 10:02:17 +08:00
|
|
|
|
|
|
|
|
2021-06-04 10:33:34 +08:00
|
|
|
class Checker:
|
2021-09-15 10:41:48 +08:00
|
|
|
"""
|
|
|
|
A base class of milvus operation checker to
|
|
|
|
a. check whether milvus is servicing
|
|
|
|
b. count operations and success rate
|
|
|
|
"""
|
2021-12-17 17:13:44 +08:00
|
|
|
|
2022-05-15 20:41:59 +08:00
|
|
|
def __init__(self, collection_name=None, shards_num=2):
|
2021-06-04 10:33:34 +08:00
|
|
|
self._succ = 0
|
|
|
|
self._fail = 0
|
2022-06-30 09:00:18 +08:00
|
|
|
self._keep_running = True
|
2022-03-07 16:20:04 +08:00
|
|
|
self.rsp_times = []
|
2021-12-07 21:45:26 +08:00
|
|
|
self.average_time = 0
|
2021-06-24 11:56:08 +08:00
|
|
|
self.c_wrap = ApiCollectionWrapper()
|
2022-06-30 09:00:18 +08:00
|
|
|
c_name = collection_name if collection_name is not None else cf.gen_unique_str(
|
|
|
|
'Checker_')
|
|
|
|
self.c_wrap.init_collection(name=c_name,
|
|
|
|
schema=cf.gen_default_collection_schema(),
|
|
|
|
shards_num=shards_num,
|
|
|
|
timeout=timeout,
|
|
|
|
enable_traceback=enable_traceback)
|
|
|
|
self.c_wrap.insert(data=cf.gen_default_list_data(nb=constants.ENTITIES_FOR_SEARCH),
|
|
|
|
timeout=timeout,
|
|
|
|
enable_traceback=enable_traceback)
|
2021-12-17 17:13:44 +08:00
|
|
|
self.initial_entities = self.c_wrap.num_entities # do as a flush
|
2021-06-04 10:33:34 +08:00
|
|
|
|
|
|
|
def total(self):
|
|
|
|
return self._succ + self._fail
|
|
|
|
|
2021-06-17 11:49:57 +08:00
|
|
|
def succ_rate(self):
|
2021-06-04 10:33:34 +08:00
|
|
|
return self._succ / self.total() if self.total() != 0 else 0
|
|
|
|
|
2022-03-07 16:20:04 +08:00
|
|
|
def check_result(self):
|
|
|
|
succ_rate = self.succ_rate()
|
|
|
|
total = self.total()
|
|
|
|
rsp_times = self.rsp_times
|
2022-06-30 09:00:18 +08:00
|
|
|
average_time = 0 if len(rsp_times) == 0 else sum(
|
|
|
|
rsp_times) / len(rsp_times)
|
2022-03-07 16:20:04 +08:00
|
|
|
max_time = 0 if len(rsp_times) == 0 else max(rsp_times)
|
2022-05-23 22:24:05 +08:00
|
|
|
min_time = 0 if len(rsp_times) == 0 else min(rsp_times)
|
2022-06-30 09:00:18 +08:00
|
|
|
checker_name = self.__class__.__name__
|
|
|
|
checkers_result = f"{checker_name}, succ_rate: {succ_rate:.2f}, total: {total:03d}, average_time: {average_time:.4f}, max_time: {max_time:.4f}, min_time: {min_time:.4f}"
|
|
|
|
log.info(checkers_result)
|
2022-03-07 16:20:04 +08:00
|
|
|
return checkers_result
|
|
|
|
|
2022-06-30 09:00:18 +08:00
|
|
|
def terminate(self):
|
|
|
|
self._keep_running = False
|
2022-07-01 09:06:23 +08:00
|
|
|
self.reset()
|
2022-06-30 09:00:18 +08:00
|
|
|
|
2021-06-04 10:33:34 +08:00
|
|
|
def reset(self):
|
|
|
|
self._succ = 0
|
|
|
|
self._fail = 0
|
2022-03-07 16:20:04 +08:00
|
|
|
self.rsp_times = []
|
2021-12-07 21:45:26 +08:00
|
|
|
self.average_time = 0
|
2021-06-04 10:33:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
class SearchChecker(Checker):
|
2021-09-16 17:23:50 +08:00
|
|
|
"""check search operations in a dependent thread"""
|
2021-12-17 17:13:44 +08:00
|
|
|
|
2022-05-15 20:41:59 +08:00
|
|
|
def __init__(self, collection_name=None, shards_num=2, replica_number=1):
|
2022-06-25 15:38:15 +08:00
|
|
|
if collection_name is None:
|
|
|
|
collection_name = cf.gen_unique_str("SearchChecker_")
|
2022-05-15 20:41:59 +08:00
|
|
|
super().__init__(collection_name=collection_name, shards_num=shards_num)
|
2022-06-30 09:00:18 +08:00
|
|
|
# do load before search
|
|
|
|
self.c_wrap.load(replica_number=replica_number)
|
|
|
|
|
|
|
|
@trace()
|
|
|
|
def search(self):
|
|
|
|
res, result = self.c_wrap.search(
|
|
|
|
data=cf.gen_vectors(5, ct.default_dim),
|
|
|
|
anns_field=ct.default_float_vec_field_name,
|
|
|
|
param={"nprobe": 32},
|
|
|
|
limit=1,
|
|
|
|
timeout=timeout,
|
|
|
|
check_task=CheckTasks.check_nothing
|
|
|
|
)
|
|
|
|
return res, result
|
|
|
|
|
|
|
|
@exception_handler()
|
|
|
|
def run_task(self):
|
|
|
|
res, result = self.search()
|
|
|
|
return res, result
|
2021-06-04 10:33:34 +08:00
|
|
|
|
2021-06-09 16:19:48 +08:00
|
|
|
def keep_running(self):
|
2022-06-30 09:00:18 +08:00
|
|
|
while self._keep_running:
|
|
|
|
self.run_task()
|
2021-06-24 11:56:08 +08:00
|
|
|
sleep(constants.WAIT_PER_OP / 10)
|
2021-06-04 10:33:34 +08:00
|
|
|
|
2021-12-17 17:13:44 +08:00
|
|
|
|
2021-06-17 11:49:57 +08:00
|
|
|
class InsertFlushChecker(Checker):
|
2021-10-02 19:44:11 +08:00
|
|
|
"""check Insert and flush operations in a dependent thread"""
|
2021-12-17 17:13:44 +08:00
|
|
|
|
2022-05-15 20:41:59 +08:00
|
|
|
def __init__(self, collection_name=None, flush=False, shards_num=2):
|
|
|
|
super().__init__(collection_name=collection_name, shards_num=shards_num)
|
2021-06-24 11:56:08 +08:00
|
|
|
self._flush = flush
|
2021-08-03 11:01:25 +08:00
|
|
|
self.initial_entities = self.c_wrap.num_entities
|
2021-06-04 10:33:34 +08:00
|
|
|
|
2021-06-09 16:19:48 +08:00
|
|
|
def keep_running(self):
|
2021-11-08 13:01:34 +08:00
|
|
|
while True:
|
2021-12-07 21:45:26 +08:00
|
|
|
t0 = time.time()
|
2022-06-30 09:00:18 +08:00
|
|
|
_, insert_result = \
|
|
|
|
self.c_wrap.insert(data=cf.gen_default_list_data(nb=constants.DELTA_PER_INS),
|
|
|
|
timeout=timeout,
|
|
|
|
enable_traceback=enable_traceback,
|
|
|
|
check_task=CheckTasks.check_nothing)
|
2021-12-07 21:45:26 +08:00
|
|
|
t1 = time.time()
|
2021-06-24 11:56:08 +08:00
|
|
|
if not self._flush:
|
|
|
|
if insert_result:
|
2022-03-07 16:20:04 +08:00
|
|
|
self.rsp_times.append(t1 - t0)
|
2022-06-30 09:00:18 +08:00
|
|
|
self.average_time = ((t1 - t0) + self.average_time * self._succ) / (self._succ + 1)
|
2021-06-17 11:49:57 +08:00
|
|
|
self._succ += 1
|
2022-06-30 09:00:18 +08:00
|
|
|
log.debug(f"insert success, time: {t1 - t0:.4f}, average_time: {self.average_time:.4f}")
|
2021-06-09 16:19:48 +08:00
|
|
|
else:
|
2021-06-17 11:49:57 +08:00
|
|
|
self._fail += 1
|
2021-06-24 11:56:08 +08:00
|
|
|
sleep(constants.WAIT_PER_OP / 10)
|
2021-06-04 10:33:34 +08:00
|
|
|
else:
|
2021-10-06 20:53:03 +08:00
|
|
|
# call flush in property num_entities
|
2021-12-07 21:45:26 +08:00
|
|
|
t0 = time.time()
|
2021-11-06 22:06:54 +08:00
|
|
|
num_entities = self.c_wrap.num_entities
|
2021-12-07 21:45:26 +08:00
|
|
|
t1 = time.time()
|
2021-11-06 22:06:54 +08:00
|
|
|
if num_entities == (self.initial_entities + constants.DELTA_PER_INS):
|
2022-03-07 16:20:04 +08:00
|
|
|
self.rsp_times.append(t1 - t0)
|
2022-06-30 09:00:18 +08:00
|
|
|
self.average_time = ((t1 - t0) + self.average_time * self._succ) / (self._succ + 1)
|
2021-06-17 11:49:57 +08:00
|
|
|
self._succ += 1
|
2022-06-30 09:00:18 +08:00
|
|
|
log.debug(f"flush success, time: {t1 - t0:.4f}, average_time: {self.average_time:.4f}")
|
2021-08-03 11:01:25 +08:00
|
|
|
self.initial_entities += constants.DELTA_PER_INS
|
2021-06-17 11:49:57 +08:00
|
|
|
else:
|
|
|
|
self._fail += 1
|
2021-06-04 10:33:34 +08:00
|
|
|
|
2021-12-17 17:13:44 +08:00
|
|
|
|
2022-06-30 09:00:18 +08:00
|
|
|
class FlushChecker(Checker):
|
|
|
|
"""check flush operations in a dependent thread"""
|
|
|
|
|
|
|
|
def __init__(self, collection_name=None, flush=False, shards_num=2):
|
|
|
|
if collection_name is None:
|
2022-07-01 09:06:23 +08:00
|
|
|
collection_name = cf.gen_unique_str("FlushChecker_")
|
2022-06-30 09:00:18 +08:00
|
|
|
super().__init__(collection_name=collection_name, shards_num=shards_num)
|
|
|
|
self._flush = flush
|
|
|
|
self.initial_entities = self.c_wrap.num_entities
|
|
|
|
|
|
|
|
@trace()
|
|
|
|
def flush(self):
|
|
|
|
num_entities = self.c_wrap.num_entities
|
2022-07-01 09:06:23 +08:00
|
|
|
if num_entities >= (self.initial_entities + constants.DELTA_PER_INS):
|
2022-06-30 09:00:18 +08:00
|
|
|
result = True
|
|
|
|
self.initial_entities += constants.DELTA_PER_INS
|
|
|
|
else:
|
|
|
|
result = False
|
|
|
|
return num_entities, result
|
|
|
|
|
|
|
|
@exception_handler()
|
|
|
|
def run_task(self):
|
|
|
|
_, result = self.c_wrap.insert(data=cf.gen_default_list_data(nb=constants.DELTA_PER_INS),
|
|
|
|
timeout=timeout,
|
|
|
|
enable_traceback=enable_traceback,
|
|
|
|
check_task=CheckTasks.check_nothing)
|
|
|
|
res, result = self.flush()
|
|
|
|
return res, result
|
|
|
|
|
|
|
|
def keep_running(self):
|
|
|
|
while self._keep_running:
|
|
|
|
self.run_task()
|
|
|
|
sleep(constants.WAIT_PER_OP / 10)
|
|
|
|
|
|
|
|
|
|
|
|
class InsertChecker(Checker):
|
|
|
|
"""check flush operations in a dependent thread"""
|
|
|
|
|
|
|
|
def __init__(self, collection_name=None, flush=False, shards_num=2):
|
|
|
|
if collection_name is None:
|
|
|
|
collection_name = cf.gen_unique_str("InsertChecker_")
|
|
|
|
super().__init__(collection_name=collection_name, shards_num=shards_num)
|
|
|
|
self._flush = flush
|
|
|
|
self.initial_entities = self.c_wrap.num_entities
|
|
|
|
|
|
|
|
@trace()
|
|
|
|
def insert(self):
|
|
|
|
res, result = self.c_wrap.insert(data=cf.gen_default_list_data(nb=constants.DELTA_PER_INS),
|
|
|
|
timeout=timeout,
|
|
|
|
enable_traceback=enable_traceback,
|
|
|
|
check_task=CheckTasks.check_nothing)
|
|
|
|
return res, result
|
|
|
|
|
|
|
|
@exception_handler()
|
|
|
|
def run_task(self):
|
|
|
|
res, result = self.insert()
|
|
|
|
return res, result
|
|
|
|
|
|
|
|
def keep_running(self):
|
|
|
|
while self._keep_running:
|
|
|
|
self.run_task()
|
|
|
|
sleep(constants.WAIT_PER_OP / 10)
|
|
|
|
|
|
|
|
|
2021-06-04 10:33:34 +08:00
|
|
|
class CreateChecker(Checker):
|
2021-10-03 08:47:55 +08:00
|
|
|
"""check create operations in a dependent thread"""
|
2021-12-17 17:13:44 +08:00
|
|
|
|
2022-06-25 15:38:15 +08:00
|
|
|
def __init__(self, collection_name=None):
|
|
|
|
if collection_name is None:
|
|
|
|
collection_name = cf.gen_unique_str("CreateChecker_")
|
|
|
|
super().__init__(collection_name=collection_name)
|
2021-06-04 10:33:34 +08:00
|
|
|
|
2022-06-30 09:00:18 +08:00
|
|
|
@trace()
|
|
|
|
def init_collection(self):
|
|
|
|
res, result = self.c_wrap.init_collection(
|
|
|
|
name=cf.gen_unique_str("CreateChecker_"),
|
|
|
|
schema=cf.gen_default_collection_schema(),
|
|
|
|
timeout=timeout,
|
|
|
|
enable_traceback=enable_traceback,
|
|
|
|
check_task=CheckTasks.check_nothing)
|
|
|
|
return res, result
|
2021-12-07 21:45:26 +08:00
|
|
|
|
2022-06-30 09:00:18 +08:00
|
|
|
@exception_handler()
|
|
|
|
def run_task(self):
|
|
|
|
res, result = self.init_collection()
|
|
|
|
if result:
|
|
|
|
self.c_wrap.drop(timeout=timeout)
|
|
|
|
return res, result
|
|
|
|
|
|
|
|
def keep_running(self):
|
|
|
|
while self._keep_running:
|
|
|
|
self.run_task()
|
2021-06-24 11:56:08 +08:00
|
|
|
sleep(constants.WAIT_PER_OP / 10)
|
2021-06-04 10:33:34 +08:00
|
|
|
|
2021-12-17 17:13:44 +08:00
|
|
|
|
2021-06-04 10:33:34 +08:00
|
|
|
class IndexChecker(Checker):
|
2021-10-04 08:30:17 +08:00
|
|
|
"""check Insert operations in a dependent thread"""
|
2021-12-17 17:13:44 +08:00
|
|
|
|
2022-06-25 15:38:15 +08:00
|
|
|
def __init__(self, collection_name=None):
|
|
|
|
if collection_name is None:
|
|
|
|
collection_name = cf.gen_unique_str("IndexChecker_")
|
|
|
|
super().__init__(collection_name=collection_name)
|
2022-06-30 09:00:18 +08:00
|
|
|
self.c_wrap.insert(data=cf.gen_default_list_data(nb=5 * constants.ENTITIES_FOR_SEARCH),
|
|
|
|
timeout=timeout, enable_traceback=enable_traceback)
|
|
|
|
# do as a flush before indexing
|
|
|
|
log.debug(f"Index ready entities: {self.c_wrap.num_entities}")
|
|
|
|
|
|
|
|
@trace()
|
|
|
|
def create_index(self):
|
|
|
|
res, result = self.c_wrap.create_index(ct.default_float_vec_field_name,
|
|
|
|
constants.DEFAULT_INDEX_PARAM,
|
|
|
|
name=cf.gen_unique_str(
|
|
|
|
'index_'),
|
|
|
|
timeout=timeout,
|
|
|
|
enable_traceback=enable_traceback,
|
|
|
|
check_task=CheckTasks.check_nothing)
|
|
|
|
return res, result
|
|
|
|
|
|
|
|
@exception_handler()
|
|
|
|
def run_task(self):
|
|
|
|
res, result = self.create_index()
|
|
|
|
if result:
|
|
|
|
self.c_wrap.drop_index(timeout=timeout)
|
|
|
|
return res, result
|
2021-06-04 10:33:34 +08:00
|
|
|
|
2021-06-09 16:19:48 +08:00
|
|
|
def keep_running(self):
|
2022-06-30 09:00:18 +08:00
|
|
|
while self._keep_running:
|
|
|
|
self.run_task()
|
|
|
|
sleep(constants.WAIT_PER_OP / 10)
|
2021-06-04 10:33:34 +08:00
|
|
|
|
2021-12-17 17:13:44 +08:00
|
|
|
|
2021-06-09 16:19:48 +08:00
|
|
|
class QueryChecker(Checker):
|
2021-10-05 20:39:14 +08:00
|
|
|
"""check query operations in a dependent thread"""
|
2021-12-17 17:13:44 +08:00
|
|
|
|
2022-05-15 20:41:59 +08:00
|
|
|
def __init__(self, collection_name=None, shards_num=2, replica_number=1):
|
2022-06-25 15:38:15 +08:00
|
|
|
if collection_name is None:
|
|
|
|
collection_name = cf.gen_unique_str("QueryChecker_")
|
2022-05-15 20:41:59 +08:00
|
|
|
super().__init__(collection_name=collection_name, shards_num=shards_num)
|
|
|
|
self.c_wrap.load(replica_number=replica_number) # do load before query
|
2022-06-30 09:00:18 +08:00
|
|
|
self.term_expr = None
|
|
|
|
|
|
|
|
@trace()
|
|
|
|
def query(self):
|
|
|
|
res, result = self.c_wrap.query(self.term_expr, timeout=timeout,
|
|
|
|
check_task=CheckTasks.check_nothing)
|
|
|
|
return res, result
|
|
|
|
|
|
|
|
@exception_handler()
|
|
|
|
def run_task(self):
|
|
|
|
int_values = []
|
|
|
|
for _ in range(5):
|
|
|
|
int_values.append(randint(0, constants.ENTITIES_FOR_SEARCH))
|
|
|
|
self.term_expr = f'{ct.default_int64_field_name} in {int_values}'
|
|
|
|
res, result= self.query()
|
|
|
|
return res, result
|
2021-06-04 10:33:34 +08:00
|
|
|
|
2021-06-09 16:19:48 +08:00
|
|
|
def keep_running(self):
|
2022-06-30 09:00:18 +08:00
|
|
|
while self._keep_running:
|
|
|
|
self.run_task()
|
|
|
|
sleep(constants.WAIT_PER_OP / 10)
|
|
|
|
|
|
|
|
|
|
|
|
class LoadChecker(Checker):
|
|
|
|
"""check load operations in a dependent thread"""
|
|
|
|
|
|
|
|
def __init__(self, collection_name=None, replica_number=1):
|
|
|
|
if collection_name is None:
|
|
|
|
collection_name = cf.gen_unique_str("DeleteChecker_")
|
|
|
|
super().__init__(collection_name=collection_name)
|
|
|
|
self.replica_number = replica_number
|
|
|
|
|
|
|
|
@trace()
|
|
|
|
def load(self):
|
|
|
|
res, result = self.c_wrap.load(replica_number=self.replica_number, timeout=timeout)
|
|
|
|
return res, result
|
|
|
|
|
|
|
|
@exception_handler()
|
|
|
|
def run_task(self):
|
|
|
|
res, result = self.load()
|
|
|
|
if result:
|
|
|
|
self.c_wrap.release()
|
|
|
|
return res, result
|
|
|
|
|
|
|
|
def keep_running(self):
|
|
|
|
while self._keep_running:
|
|
|
|
self.run_task()
|
2021-06-28 14:14:13 +08:00
|
|
|
sleep(constants.WAIT_PER_OP / 10)
|
2021-12-02 22:49:52 +08:00
|
|
|
|
2021-12-17 17:13:44 +08:00
|
|
|
|
2022-05-23 22:24:05 +08:00
|
|
|
class DeleteChecker(Checker):
|
|
|
|
"""check delete operations in a dependent thread"""
|
|
|
|
|
|
|
|
def __init__(self, collection_name=None):
|
2022-06-25 15:38:15 +08:00
|
|
|
if collection_name is None:
|
|
|
|
collection_name = cf.gen_unique_str("DeleteChecker_")
|
2022-05-23 22:24:05 +08:00
|
|
|
super().__init__(collection_name=collection_name)
|
|
|
|
self.c_wrap.load() # load before query
|
2022-06-30 09:00:18 +08:00
|
|
|
term_expr = f'{ct.default_int64_field_name} > 0'
|
|
|
|
res, _ = self.c_wrap.query(term_expr, output_fields=[
|
|
|
|
ct.default_int64_field_name])
|
|
|
|
self.ids = [r[ct.default_int64_field_name] for r in res]
|
|
|
|
self.expr = None
|
|
|
|
|
|
|
|
@trace()
|
|
|
|
def delete(self):
|
|
|
|
res, result = self.c_wrap.delete(expr=self.expr, timeout=timeout)
|
|
|
|
return res, result
|
|
|
|
|
|
|
|
@exception_handler()
|
|
|
|
def run_task(self):
|
|
|
|
delete_ids = self.ids.pop()
|
|
|
|
self.expr = f'{ct.default_int64_field_name} in {[delete_ids]}'
|
|
|
|
res, result = self.delete()
|
|
|
|
return res, result
|
2022-05-23 22:24:05 +08:00
|
|
|
|
|
|
|
def keep_running(self):
|
2022-06-30 09:00:18 +08:00
|
|
|
while self._keep_running:
|
|
|
|
self.run_task()
|
2022-05-23 22:24:05 +08:00
|
|
|
sleep(constants.WAIT_PER_OP / 10)
|
|
|
|
|
|
|
|
|
|
|
|
class CompactChecker(Checker):
|
|
|
|
"""check compact operations in a dependent thread"""
|
|
|
|
|
|
|
|
def __init__(self, collection_name=None):
|
2022-06-25 15:38:15 +08:00
|
|
|
if collection_name is None:
|
|
|
|
collection_name = cf.gen_unique_str("CompactChecker_")
|
2022-05-23 22:24:05 +08:00
|
|
|
super().__init__(collection_name=collection_name)
|
|
|
|
self.ut = ApiUtilityWrapper()
|
2022-06-30 09:00:18 +08:00
|
|
|
self.c_wrap.load() # load before compact
|
|
|
|
|
|
|
|
@trace()
|
|
|
|
def compact(self):
|
|
|
|
res, result = self.c_wrap.compact(timeout=timeout)
|
|
|
|
self.c_wrap.wait_for_compaction_completed()
|
|
|
|
self.c_wrap.get_compaction_plans()
|
|
|
|
return res, result
|
|
|
|
|
|
|
|
@exception_handler()
|
|
|
|
def run_task(self):
|
|
|
|
res, result = self.compact()
|
|
|
|
return res, result
|
2022-05-23 22:24:05 +08:00
|
|
|
|
|
|
|
def keep_running(self):
|
2022-06-30 09:00:18 +08:00
|
|
|
while self._keep_running:
|
|
|
|
self.run_task()
|
2022-05-23 22:24:05 +08:00
|
|
|
sleep(constants.WAIT_PER_OP / 10)
|
|
|
|
|
|
|
|
|
|
|
|
class DropChecker(Checker):
|
|
|
|
"""check drop operations in a dependent thread"""
|
|
|
|
|
|
|
|
def __init__(self, collection_name=None):
|
2022-06-25 15:38:15 +08:00
|
|
|
if collection_name is None:
|
|
|
|
collection_name = cf.gen_unique_str("DropChecker_")
|
2022-05-23 22:24:05 +08:00
|
|
|
super().__init__(collection_name=collection_name)
|
2022-06-30 09:00:18 +08:00
|
|
|
|
|
|
|
@trace()
|
|
|
|
def drop(self):
|
|
|
|
res, result = self.c_wrap.drop()
|
|
|
|
return res, result
|
|
|
|
|
|
|
|
def run_task(self):
|
|
|
|
res, result = self.drop()
|
|
|
|
return res, result
|
2022-05-23 22:24:05 +08:00
|
|
|
|
|
|
|
def keep_running(self):
|
2022-06-30 09:00:18 +08:00
|
|
|
while self._keep_running:
|
|
|
|
res, result = self.run_task()
|
2022-05-23 22:24:05 +08:00
|
|
|
if result:
|
2022-06-30 09:00:18 +08:00
|
|
|
self.c_wrap.init_collection(
|
|
|
|
name=cf.gen_unique_str("CreateChecker_"),
|
|
|
|
schema=cf.gen_default_collection_schema(),
|
|
|
|
timeout=timeout,
|
|
|
|
check_task=CheckTasks.check_nothing)
|
2022-05-23 22:24:05 +08:00
|
|
|
sleep(constants.WAIT_PER_OP / 10)
|
|
|
|
|
|
|
|
|
|
|
|
class LoadBalanceChecker(Checker):
|
|
|
|
"""check loadbalance operations in a dependent thread"""
|
|
|
|
|
|
|
|
def __init__(self, collection_name=None):
|
2022-06-25 15:38:15 +08:00
|
|
|
if collection_name is None:
|
|
|
|
collection_name = cf.gen_unique_str("LoadBalanceChecker_")
|
2022-05-23 22:24:05 +08:00
|
|
|
super().__init__(collection_name=collection_name)
|
|
|
|
self.utility_wrap = ApiUtilityWrapper()
|
2022-06-30 09:00:18 +08:00
|
|
|
self.c_wrap.load()
|
|
|
|
self.sealed_segment_ids = None
|
|
|
|
self.dst_node_ids = None
|
|
|
|
self.src_node_id = None
|
|
|
|
|
|
|
|
@trace()
|
|
|
|
def load_balance(self):
|
|
|
|
res, result = self.utility_wrap.load_balance(
|
|
|
|
self.c_wrap.name, self.src_node_id, self.dst_node_ids, self.sealed_segment_ids)
|
|
|
|
return res, result
|
|
|
|
|
|
|
|
def prepare(self):
|
|
|
|
"""prepare load balance params"""
|
|
|
|
res, _ = self.c_wrap.get_replicas()
|
|
|
|
# find a group which has multi nodes
|
|
|
|
group_nodes = []
|
|
|
|
for g in res.groups:
|
|
|
|
if len(g.group_nodes) >= 2:
|
|
|
|
group_nodes = list(g.group_nodes)
|
|
|
|
break
|
|
|
|
self.src_node_id = group_nodes[0]
|
|
|
|
self.dst_node_ids = group_nodes[1:]
|
|
|
|
res, _ = self.utility_wrap.get_query_segment_info(self.c_wrap.name)
|
|
|
|
segment_distribution = cf.get_segment_distribution(res)
|
|
|
|
self.sealed_segment_ids = segment_distribution[self.src_node_id]["sealed"]
|
|
|
|
|
|
|
|
@exception_handler()
|
|
|
|
def run_task(self):
|
|
|
|
self.prepare()
|
|
|
|
res, result = self.load_balance()
|
|
|
|
return res, result
|
2022-05-23 22:24:05 +08:00
|
|
|
|
|
|
|
def keep_running(self):
|
2022-06-30 09:00:18 +08:00
|
|
|
while self._keep_running:
|
|
|
|
self.run_task()
|
|
|
|
sleep(constants.WAIT_PER_OP / 10)
|
2022-05-23 22:24:05 +08:00
|
|
|
|
|
|
|
|
2022-05-15 20:41:59 +08:00
|
|
|
class BulkLoadChecker(Checker):
|
|
|
|
"""check bulk load operations in a dependent thread"""
|
|
|
|
|
2022-06-30 09:00:18 +08:00
|
|
|
def __init__(self, collection_name=None, files=[]):
|
2022-06-25 15:38:15 +08:00
|
|
|
if collection_name is None:
|
|
|
|
collection_name = cf.gen_unique_str("BulkLoadChecker_")
|
|
|
|
super().__init__(collection_name=collection_name)
|
2022-05-15 20:41:59 +08:00
|
|
|
self.utility_wrap = ApiUtilityWrapper()
|
|
|
|
self.schema = cf.gen_default_collection_schema()
|
2022-06-30 09:00:18 +08:00
|
|
|
self.files = files
|
2022-05-20 09:31:57 +08:00
|
|
|
self.row_based = True
|
|
|
|
self.recheck_failed_task = False
|
2022-05-15 20:41:59 +08:00
|
|
|
self.failed_tasks = []
|
2022-06-30 09:00:18 +08:00
|
|
|
self.c_name = None
|
2022-05-15 20:41:59 +08:00
|
|
|
|
2022-05-20 09:31:57 +08:00
|
|
|
def update(self, files=None, schema=None, row_based=None):
|
|
|
|
if files is not None:
|
2022-05-15 20:41:59 +08:00
|
|
|
self.files = files
|
2022-05-20 09:31:57 +08:00
|
|
|
if schema is not None:
|
2022-05-15 20:41:59 +08:00
|
|
|
self.schema = schema
|
2022-05-20 09:31:57 +08:00
|
|
|
if row_based is not None:
|
|
|
|
self.row_based = row_based
|
2022-05-15 20:41:59 +08:00
|
|
|
|
2022-06-30 09:00:18 +08:00
|
|
|
@trace()
|
|
|
|
def bulk_load(self):
|
|
|
|
task_ids, result = self.utility_wrap.bulk_load(collection_name=self.c_name,
|
|
|
|
row_based=self.row_based,
|
|
|
|
files=self.files)
|
|
|
|
completed, result = self.utility_wrap.wait_for_bulk_load_tasks_completed(task_ids=task_ids, timeout=30)
|
|
|
|
return task_ids, completed
|
|
|
|
|
|
|
|
@exception_handler()
|
|
|
|
def run_task(self):
|
|
|
|
if self.recheck_failed_task and self.failed_tasks:
|
|
|
|
self.c_name = self.failed_tasks.pop(0)
|
|
|
|
log.debug(f"check failed task: {self.c_name}")
|
2021-12-02 22:49:52 +08:00
|
|
|
else:
|
2022-06-30 09:00:18 +08:00
|
|
|
self.c_name = cf.gen_unique_str("BulkLoadChecker_")
|
|
|
|
self.c_wrap.init_collection(name=self.c_name, schema=self.schema)
|
|
|
|
# import data
|
|
|
|
task_ids, completed = self.bulk_load()
|
|
|
|
if not completed:
|
|
|
|
self.failed_tasks.append(self.c_name)
|
|
|
|
return task_ids, completed
|
2022-06-25 15:38:15 +08:00
|
|
|
|
2022-06-30 09:00:18 +08:00
|
|
|
def keep_running(self):
|
|
|
|
while self._keep_running:
|
|
|
|
self.run_task()
|
|
|
|
sleep(constants.WAIT_PER_OP / 10)
|