Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 : #include "strategy/hash_strategy.h"
11 : #include "dgw_client.h"
12 : #include "common/bqs_log.h"
13 : #include "entity_manager.h"
14 : #include "strategy/strategy_manager.h"
15 :
16 : namespace dgw {
17 4 : FsmStatus HashStrategy::Search(const uint32_t groupId, const uint64_t transId, std::vector<EntityPtr> &selEntities,
18 : const uint32_t resIndex)
19 : {
20 4 : const std::vector<EntityPtr> &entitiesInGroup = EntityManager::Instance(resIndex).GetEntitiesInGroup(groupId);
21 4 : if (entitiesInGroup.empty()) {
22 1 : DGW_LOG_ERROR("No entities in group, groupId:%u, transId:%lu", groupId, transId);
23 1 : return FsmStatus::FSM_FAILED;
24 : }
25 3 : if (transId == 0UL) {
26 1 : DGW_LOG_ERROR("transId is invalid, transId:%lu", transId);
27 1 : return FsmStatus::FSM_FAILED;
28 : }
29 :
30 2 : const uint64_t idx = transId % entitiesInGroup.size();
31 2 : auto &selEntity = entitiesInGroup[idx];
32 2 : selEntities.push_back(selEntity);
33 2 : DGW_LOG_DEBUG("Select entity id:%u type:%s from group:%u success, index:%lu.",
34 : selEntity->GetId(), selEntity->GetTypeDesc().c_str(), groupId, idx);
35 2 : return FsmStatus::FSM_SUCCESS;
36 : }
37 :
38 : REGISTER_STRATEGY(HASH, HashStrategy);
39 : }
|