@@ -944,6 +944,211 @@ void increaseDataTypeArrayCurrentValue(keysizeInfo *keysize_array, int low, int
944
944
}
945
945
}
946
946
947
+ void scaleHashKeySizeArray (client * c , long value ) {
948
+ int length = c -> db -> hashes_array_length ;
949
+ int high_bound = c -> db -> hashes_array [length - 1 ].element_size ;
950
+ int base = high_bound ;
951
+ int count = 0 ;
952
+ while (high_bound < value ) {
953
+ count ++ ;
954
+ high_bound = high_bound * 2 ;
955
+ }
956
+ keysizeInfo * new_array = zmalloc (sizeof (keysizeInfo ) * (count + length ));
957
+ for (int i = 0 ; i < length ; i ++ ) {
958
+ new_array [i ].element_size = c -> db -> hashes_array [i ].element_size ;
959
+ new_array [i ].num = c -> db -> hashes_array [i ].num ;
960
+ }
961
+ for (int i = length ; i < (count + length ); i ++ ) {
962
+ base *= 2 ;
963
+ new_array [i ].element_size = base ;
964
+ new_array [i ].num = 0 ;
965
+ }
966
+ keysizeInfo * old_array = c -> db -> hashes_array ;
967
+ zfree (old_array );
968
+ c -> db -> hashes_array = new_array ;
969
+ c -> db -> hashes_array_length = count + length ;
970
+ }
971
+
972
+ void updateHashKeySizeArray (client * c , long previous , long curr ) {
973
+ int low = 0 ;
974
+ int high = c -> db -> hashes_array_length - 1 ;
975
+ if (curr > c -> db -> hashes_array [high ].element_size ) {
976
+ scaleHashKeySizeArray (c , curr );
977
+ }
978
+
979
+ high = c -> db -> hashes_array_length - 1 ;
980
+ if (previous != 0 ) {
981
+ decreaseDataTypeArrayPreviousValue (c -> db -> hashes_array , low , high , previous );
982
+ }
983
+ if (curr != 0 ) {
984
+ increaseDataTypeArrayCurrentValue (c -> db -> hashes_array , low , high , curr );
985
+ }
986
+ }
987
+
988
+ void scaleListKeySizeArray (client * c , long value ) {
989
+ int length = c -> db -> lists_array_length ;
990
+ int high_bound = c -> db -> lists_array [length - 1 ].element_size ;
991
+ int base = high_bound ;
992
+ int count = 0 ;
993
+ while (high_bound < value ) {
994
+ count ++ ;
995
+ high_bound = high_bound * 2 ;
996
+ }
997
+ keysizeInfo * new_array = zmalloc (sizeof (keysizeInfo ) * (count + length ));
998
+ for (int i = 0 ; i < length ; i ++ ) {
999
+ new_array [i ].element_size = c -> db -> lists_array [i ].element_size ;
1000
+ new_array [i ].num = c -> db -> lists_array [i ].num ;
1001
+ }
1002
+ for (int i = length ; i < (count + length ); i ++ ) {
1003
+ base *= 2 ;
1004
+ new_array [i ].element_size = base ;
1005
+ new_array [i ].num = 0 ;
1006
+ }
1007
+ keysizeInfo * old_array = c -> db -> lists_array ;
1008
+ zfree (old_array );
1009
+ c -> db -> lists_array = new_array ;
1010
+ c -> db -> lists_array_length = count + length ;
1011
+ }
1012
+
1013
+ void updateListKeySizeArray (client * c , long previous , long curr ) {
1014
+ int low = 0 ;
1015
+ int high = c -> db -> lists_array_length - 1 ;
1016
+ if (curr > c -> db -> lists_array [high ].element_size ) {
1017
+ scaleListKeySizeArray (c , curr );
1018
+ }
1019
+
1020
+ high = c -> db -> lists_array_length - 1 ;
1021
+ if (previous != 0 ) {
1022
+ decreaseDataTypeArrayPreviousValue (c -> db -> lists_array , low , high , previous );
1023
+ }
1024
+ if (curr != 0 ) {
1025
+ increaseDataTypeArrayCurrentValue (c -> db -> lists_array , low , high , curr );
1026
+ }
1027
+ }
1028
+
1029
+ void scaleSetKeySizeArray (client * c , long value ) {
1030
+ int length = c -> db -> sets_array_length ;
1031
+ int high_bound = c -> db -> sets_array [length - 1 ].element_size ;
1032
+ int base = high_bound ;
1033
+ int count = 0 ;
1034
+ while (high_bound < value ) {
1035
+ count ++ ;
1036
+ high_bound = high_bound * 2 ;
1037
+ }
1038
+ keysizeInfo * new_array = zmalloc (sizeof (keysizeInfo ) * (count + length ));
1039
+ for (int i = 0 ; i < length ; i ++ ) {
1040
+ new_array [i ].element_size = c -> db -> sets_array [i ].element_size ;
1041
+ new_array [i ].num = c -> db -> sets_array [i ].num ;
1042
+ }
1043
+ for (int i = length ; i < (count + length ); i ++ ) {
1044
+ base *= 2 ;
1045
+ new_array [i ].element_size = base ;
1046
+ new_array [i ].num = 0 ;
1047
+ }
1048
+ keysizeInfo * old_array = c -> db -> sets_array ;
1049
+ zfree (old_array );
1050
+ c -> db -> sets_array = new_array ;
1051
+ c -> db -> sets_array_length = count + length ;
1052
+ }
1053
+
1054
+ void updateSetKeySizeArray (client * c , long previous , long curr ) {
1055
+ int low = 0 ;
1056
+ int high = c -> db -> sets_array_length - 1 ;
1057
+ if (curr > c -> db -> sets_array [high ].element_size ) {
1058
+ scaleSetKeySizeArray (c , curr );
1059
+ }
1060
+
1061
+ high = c -> db -> sets_array_length - 1 ;
1062
+ if (previous != 0 ) {
1063
+ decreaseDataTypeArrayPreviousValue (c -> db -> sets_array , low , high , previous );
1064
+ }
1065
+ if (curr != 0 ) {
1066
+ increaseDataTypeArrayCurrentValue (c -> db -> sets_array , low , high , curr );
1067
+ }
1068
+ }
1069
+
1070
+ void scaleStringKeySizeArray (client * c , long value ) {
1071
+ int length = c -> db -> strings_array_length ;
1072
+ int high_bound = c -> db -> strings_array [length - 1 ].element_size ;
1073
+ int base = high_bound ;
1074
+ int count = 0 ;
1075
+ while (high_bound < value ) {
1076
+ count ++ ;
1077
+ high_bound = high_bound * 2 ;
1078
+ }
1079
+ keysizeInfo * new_array = zmalloc (sizeof (keysizeInfo ) * (count + length ));
1080
+ for (int i = 0 ; i < length ; i ++ ) {
1081
+ new_array [i ].element_size = c -> db -> strings_array [i ].element_size ;
1082
+ new_array [i ].num = c -> db -> strings_array [i ].num ;
1083
+ }
1084
+ for (int i = length ; i < (count + length ); i ++ ) {
1085
+ base *= 2 ;
1086
+ new_array [i ].element_size = base ;
1087
+ new_array [i ].num = 0 ;
1088
+ }
1089
+ keysizeInfo * old_array = c -> db -> strings_array ;
1090
+ zfree (old_array );
1091
+ c -> db -> strings_array = new_array ;
1092
+ c -> db -> strings_array_length = count + length ;
1093
+ }
1094
+
1095
+ void updateStringKeySizeArray (client * c , long previous , long curr ) {
1096
+ int low = 0 ;
1097
+ int high = c -> db -> strings_array_length - 1 ;
1098
+ if (curr > c -> db -> strings_array [high ].element_size ) {
1099
+ scaleStringKeySizeArray (c , curr );
1100
+ }
1101
+
1102
+ high = c -> db -> strings_array_length - 1 ;
1103
+ if (previous != 0 ) {
1104
+ decreaseDataTypeArrayPreviousValue (c -> db -> strings_array , low , high , previous );
1105
+ }
1106
+ if (curr != 0 ) {
1107
+ increaseDataTypeArrayCurrentValue (c -> db -> strings_array , low , high , curr );
1108
+ }
1109
+ }
1110
+
1111
+ void scaleZsetKeySizeArray (client * c , long value ) {
1112
+ int length = c -> db -> zsets_array_length ;
1113
+ int high_bound = c -> db -> zsets_array [length - 1 ].element_size ;
1114
+ int base = high_bound ;
1115
+ int count = 0 ;
1116
+ while (high_bound < value ) {
1117
+ count ++ ;
1118
+ high_bound = high_bound * 2 ;
1119
+ }
1120
+ keysizeInfo * new_array = zmalloc (sizeof (keysizeInfo ) * (count + length ));
1121
+ for (int i = 0 ; i < length ; i ++ ) {
1122
+ new_array [i ].element_size = c -> db -> zsets_array [i ].element_size ;
1123
+ new_array [i ].num = c -> db -> zsets_array [i ].num ;
1124
+ }
1125
+ for (int i = length ; i < (count + length ); i ++ ) {
1126
+ base *= 2 ;
1127
+ new_array [i ].element_size = base ;
1128
+ new_array [i ].num = 0 ;
1129
+ }
1130
+ keysizeInfo * old_array = c -> db -> zsets_array ;
1131
+ zfree (old_array );
1132
+ c -> db -> zsets_array = new_array ;
1133
+ c -> db -> zsets_array_length = count + length ;
1134
+ }
1135
+
1136
+ void updateZsetKeySizeArray (client * c , long previous , long curr ) {
1137
+ int low = 0 ;
1138
+ int high = c -> db -> zsets_array_length - 1 ;
1139
+ if (curr > c -> db -> zsets_array [high ].element_size ) {
1140
+ scaleZsetKeySizeArray (c , curr );
1141
+ }
1142
+
1143
+ high = c -> db -> lists_array_length - 1 ;
1144
+ if (previous != 0 ) {
1145
+ decreaseDataTypeArrayPreviousValue (c -> db -> zsets_array , low , high , previous );
1146
+ }
1147
+ if (curr != 0 ) {
1148
+ increaseDataTypeArrayCurrentValue (c -> db -> zsets_array , low , high , curr );
1149
+ }
1150
+ }
1151
+
947
1152
/* Return the mean of all the samples. */
948
1153
long long getInstantaneousMetric (int metric ) {
949
1154
int j ;
0 commit comments