@@ -884,7 +884,7 @@ const std::string InfoCmd::kRocksDBSection = "rocksdb";
884884const std::string InfoCmd::kDebugSection = " debug" ;
885885const std::string InfoCmd::kCommandStatsSection = " commandstats" ;
886886const std::string InfoCmd::kCacheSection = " cache" ;
887-
887+ const std::string InfoCmd:: kBigKeysSection = " bigkeys " ;
888888
889889const std::string ClientCmd::KILLTYPE_NORMAL = " normal" ;
890890const std::string ClientCmd::KILLTYPE_PUBSUB = " pubsub" ;
@@ -910,6 +910,8 @@ void InfoCmd::DoInitial() {
910910 keyspace_scan_dbs_ = g_pika_server->GetAllDBName ();
911911 } else if (strcasecmp (argv_[1 ].data (), kServerSection .data ()) == 0 ) {
912912 info_section_ = kInfoServer ;
913+ } else if (strcasecmp (argv_[1 ].data (), " bigkeys" ) == 0 ) {
914+ info_section_ = kInfoBigKeys ;
913915 } else if (strcasecmp (argv_[1 ].data (), kClientsSection .data ()) == 0 ) {
914916 info_section_ = kInfoClients ;
915917 } else if (strcasecmp (argv_[1 ].data (), kStatsSection .data ()) == 0 ) {
@@ -994,6 +996,9 @@ void InfoCmd::Do() {
994996 InfoReplication (info);
995997 info.append (" \r\n " );
996998 InfoKeyspace (info);
999+ info.append (" \r\n " );
1000+ InfoBigKeys (info);
1001+ info.append (" \r\n " );
9971002 break ;
9981003 case kInfoAll :
9991004 InfoServer (info);
@@ -1017,6 +1022,9 @@ void InfoCmd::Do() {
10171022 InfoKeyspace (info);
10181023 info.append (" \r\n " );
10191024 InfoRocksDB (info);
1025+ info.append (" \r\n " );
1026+ InfoBigKeys (info);
1027+ info.append (" \r\n " );
10201028 break ;
10211029 case kInfoServer :
10221030 InfoServer (info);
@@ -1054,6 +1062,9 @@ void InfoCmd::Do() {
10541062 case kInfoCache :
10551063 InfoCache (info, db_);
10561064 break ;
1065+ case kInfoBigKeys :
1066+ InfoBigKeys (info);
1067+ break ;
10571068 default :
10581069 // kInfoErr is nothing
10591070 break ;
@@ -1094,7 +1105,21 @@ void InfoCmd::InfoServer(std::string& info) {
10941105
10951106 info.append (tmp_stream.str ());
10961107}
1097-
1108+ void InfoCmd::InfoBigKeys (std::string& info) {
1109+ std::stringstream tmp_stream;
1110+ std::shared_lock db_rwl (g_pika_server->dbs_rw_ );
1111+ for (const auto & db_item : g_pika_server->dbs_ ) {
1112+ if (!db_item.second ) {
1113+ continue ;
1114+ }
1115+ std::vector<storage::BigKeyInfo> bigkeys;
1116+ db_item.second ->storage ()->GetBigKeyStatistics (&bigkeys);
1117+ std::string bigkey_info;
1118+ storage::FormatBigKeyStatistics (bigkeys, &bigkey_info, g_pika_conf->bigkeys_show_limit ());
1119+ tmp_stream << bigkey_info;
1120+ }
1121+ info.append (tmp_stream.str ());
1122+ }
10981123void InfoCmd::InfoClients (std::string& info) {
10991124 std::stringstream tmp_stream;
11001125 tmp_stream << " # Clients"
@@ -1833,7 +1858,27 @@ void ConfigCmd::ConfigGet(std::string& ret) {
18331858 EncodeString (&config_body, " max-cache-statistic-keys" );
18341859 EncodeNumber (&config_body, g_pika_conf->max_cache_statistic_keys ());
18351860 }
1836-
1861+ // big keys
1862+ if (pstd::stringmatch (pattern.data (), " BIGKEYS_SHOW_LIMIT" , 1 )) {
1863+ elements += 2 ;
1864+ EncodeString (&config_body, " BIGKEYS_SHOW_LIMIT" );
1865+ EncodeNumber (&config_body, g_pika_conf->bigkeys_show_limit ());
1866+ }
1867+ if (pstd::stringmatch (pattern.data (), " bigkeys_member_threshold" , 1 )) {
1868+ elements += 2 ;
1869+ EncodeString (&config_body, " bigkeys_member_threshold" );
1870+ EncodeNumber (&config_body, g_pika_conf->bigkeys_member_threshold ());
1871+ }
1872+ if (pstd::stringmatch (pattern.data (), " bigkeys_key_value_length_threshold" , 1 )) {
1873+ elements += 2 ;
1874+ EncodeString (&config_body, " bigkeys_key_value_length_threshold" );
1875+ EncodeNumber (&config_body, g_pika_conf->bigkeys_key_value_length_threshold ());
1876+ }
1877+ if (pstd::stringmatch (pattern.data (), " bigkeys_log_interval" , 1 )) {
1878+ elements += 2 ;
1879+ EncodeString (&config_body, " bigkeys_log_interval" );
1880+ EncodeNumber (&config_body, g_pika_conf->bigkeys_log_interval ());
1881+ }
18371882 if (pstd::stringmatch (pattern.data (), " small-compaction-threshold" , 1 ) != 0 ) {
18381883 elements += 2 ;
18391884 EncodeString (&config_body, " small-compaction-threshold" );
@@ -2963,6 +3008,35 @@ void ConfigCmd::ConfigSet(std::shared_ptr<DB> db) {
29633008 }
29643009 g_pika_conf->SetMaxConnRbufSize (static_cast <int >(ival));
29653010 res_.AppendStringRaw (" +OK\r\n " );
3011+ // big keys
3012+ } else if (set_item == " BIGKEYS_SHOW_LIMIT" ) {
3013+ if (!pstd::string2int (value.data (), value.size (), &ival) || ival < 0 ) {
3014+ res_.AppendStringRaw (" -ERR Invalid argument '" + value + " ' for CONFIG SET 'BIGKEYS_SHOW_LIMIT'\r\n " );
3015+ return ;
3016+ }
3017+ g_pika_conf->SetBigkeysShowLimit (ival);
3018+ res_.AppendStringRaw (" +OK\r\n " );
3019+ } else if (set_item == " bigkeys_member_threshold" ) {
3020+ if (!pstd::string2int (value.data (), value.size (), &ival) || ival < 0 ) {
3021+ res_.AppendStringRaw (" -ERR Invalid argument '" + value + " ' for CONFIG SET 'bigkeys_member_threshold'\r\n " );
3022+ return ;
3023+ }
3024+ g_pika_conf->SetBigkeysMemberCountThreshold (ival);
3025+ res_.AppendStringRaw (" +OK\r\n " );
3026+ } else if (set_item == " bigkeys_key_value_length_threshold" ) {
3027+ if (!pstd::string2int (value.data (), value.size (), &ival) || ival < 0 ) {
3028+ res_.AppendStringRaw (" -ERR Invalid argument '" + value + " ' for CONFIG SET 'bigkeys_key_value_length_threshold'\r\n " );
3029+ return ;
3030+ }
3031+ g_pika_conf->SetBigkeysKeyValueLengthThreshold (ival);
3032+ res_.AppendStringRaw (" +OK\r\n " );
3033+ } else if (set_item == " bigkeys_log_interval" ) {
3034+ if (!pstd::string2int (value.data (), value.size (), &ival) || ival < 0 ) {
3035+ res_.AppendStringRaw (" -ERR Invalid argument '" + value + " ' for CONFIG SET 'bigkeys_log_interval'\r\n " );
3036+ return ;
3037+ }
3038+ g_pika_conf->SetBigkeysLogInterval (ival);
3039+ res_.AppendStringRaw (" +OK\r\n " );
29663040 } else {
29673041 res_.AppendStringRaw (" -ERR Unsupported CONFIG parameter: " + set_item + " \r\n " );
29683042 }
0 commit comments