@@ -791,9 +791,54 @@ int64_t ComputePrefixMatchBlocks(const std::vector<std::set<std::string>> &specs
791791 return prefix_len;
792792}
793793
794- bool IsFullLocationSpecGroup (const LocationSpecGroup &group) {
795- const auto &name = group.name ();
796- return name.rfind (" full" , 0 ) == 0 || name.rfind (" FULL" , 0 ) == 0 ;
794+ ErrorCode ClassifySpecGroups (RequestContext *request_context,
795+ const std::vector<LocationSpecGroup> &location_spec_groups,
796+ std::vector<const LocationSpecGroup *> &full_groups,
797+ std::vector<const LocationSpecGroup *> &mamba_state_groups) {
798+ full_groups.clear ();
799+ mamba_state_groups.clear ();
800+ for (const auto &group : location_spec_groups) {
801+ const auto &group_name = group.name ();
802+ const char category = group_name.empty () ? ' ?' : group_name.front ();
803+ switch (category) {
804+ case ' F' :
805+ full_groups.push_back (&group);
806+ break ;
807+ case ' L' :
808+ mamba_state_groups.push_back (&group);
809+ break ;
810+ case ' W' :
811+ case ' C' :
812+ case ' E' :
813+ case ' X' : {
814+ std::string error_msg =
815+ " unsupported location spec category for QT_PREFIX_MATCH_WITH_MAMBA, group: " + group_name +
816+ " , category: " + std::string (1 , category);
817+ request_context->error_tracer ()->AddErrorMsg (error_msg);
818+ KVCM_LOG_WARN (" %s" , error_msg.c_str ());
819+ return EC_BADARGS ;
820+ }
821+ default : {
822+ std::string error_msg =
823+ " invalid location spec category for QT_PREFIX_MATCH_WITH_MAMBA, group: " + group_name +
824+ " , category: " + std::string (1 , category);
825+ request_context->error_tracer ()->AddErrorMsg (error_msg);
826+ KVCM_LOG_WARN (" %s" , error_msg.c_str ());
827+ return EC_BADARGS ;
828+ }
829+ }
830+ }
831+
832+ if (full_groups.empty () || mamba_state_groups.empty ()) {
833+ std::string group_names = Jsonizable::ToJsonString (location_spec_groups);
834+ std::string error_msg =
835+ full_groups.empty () ? " no full location spec group" : " no mamba state location spec group" ;
836+ error_msg += " , location_spec_groups: " + group_names;
837+ request_context->error_tracer ()->AddErrorMsg (error_msg);
838+ KVCM_LOG_WARN (" %s" , error_msg.c_str ());
839+ return EC_BADARGS ;
840+ }
841+ return EC_OK ;
797842}
798843
799844bool HasAllLocationSpecGroups (const std::set<std::string> &spec_names,
@@ -1814,21 +1859,9 @@ ErrorCode MetaSearcher::PrefixMatchWithMambaByHost(RequestContext *request_conte
18141859
18151860 std::vector<const LocationSpecGroup *> full_groups;
18161861 std::vector<const LocationSpecGroup *> mamba_state_groups;
1817- for (const auto &group : location_spec_groups) {
1818- if (IsFullLocationSpecGroup (group)) {
1819- full_groups.push_back (&group);
1820- } else {
1821- mamba_state_groups.push_back (&group);
1822- }
1823- }
1824- if (full_groups.empty () || mamba_state_groups.empty ()) {
1825- std::string group_names = Jsonizable::ToJsonString (location_spec_groups);
1826- std::string error_msg =
1827- full_groups.empty () ? " no full location spec group" : " no mamba state location spec group" ;
1828- error_msg += " , location_spec_groups: " + group_names;
1829- request_context->error_tracer ()->AddErrorMsg (error_msg);
1830- KVCM_LOG_WARN (" %s" , error_msg.c_str ());
1831- return EC_BADARGS ;
1862+ auto ec = ClassifySpecGroups (request_context, location_spec_groups, full_groups, mamba_state_groups);
1863+ if (ec != EC_OK ) {
1864+ return ec;
18321865 }
18331866 if (p2p_host_count == 0 ) {
18341867 return PrefixMatchWithMambaByHostWithoutP2P (meta_indexer_.get (),
0 commit comments