@@ -15,6 +15,7 @@ namespace CommandInfoUpdater
15
15
/// </summary>
16
16
public class CommandInfoUpdater
17
17
{
18
+ const int QUERY_CMD_BATCH_SIZE = 25 ;
18
19
private static readonly string CommandInfoFileName = "RespCommandsInfo.json" ;
19
20
private static readonly string GarnetCommandInfoJsonPath = "GarnetCommandsInfo.json" ;
20
21
@@ -63,35 +64,43 @@ public static bool TryUpdateCommandInfo(string outputDir, int respServerPort, IP
63
64
var commandsToQuery = commandsToAdd . Keys . Select ( k => k . Command )
64
65
. Where ( c => ! garnetCommandsInfo . ContainsKey ( c ) || ! garnetCommandsInfo [ c ] . IsInternal ) . ToArray ( ) ;
65
66
66
- if ( commandsToQuery . Length > 0 && ! TryGetCommandsInfo ( commandsToQuery , respServerPort , respServerHost ,
67
- logger , out queriedCommandsInfo ) )
67
+ if ( commandsToQuery . Length > 0 )
68
68
{
69
- logger . LogError ( "Unable to get RESP command info from local RESP server." ) ;
70
- return false ;
69
+ for ( var i = 0 ; i < commandsToQuery . Length ; i += QUERY_CMD_BATCH_SIZE )
70
+ {
71
+ var batchToQuery = commandsToQuery . Skip ( i ) . Take ( QUERY_CMD_BATCH_SIZE ) . ToArray ( ) ;
72
+ if ( ! TryGetCommandsInfo ( batchToQuery , respServerPort , respServerHost ,
73
+ logger , ref queriedCommandsInfo ) )
74
+ {
75
+ logger . LogError ( "Unable to get RESP command info from local RESP server." ) ;
76
+ return false ;
77
+ }
78
+ }
71
79
}
72
80
73
81
var additionalCommandsInfo = new Dictionary < string , RespCommandsInfo > ( ) ;
74
82
foreach ( var cmd in garnetCommandsInfo . Keys . Union ( queriedCommandsInfo . Keys ) )
75
83
{
76
84
if ( ! additionalCommandsInfo . ContainsKey ( cmd ) )
77
85
{
78
- var baseCommandInfo = queriedCommandsInfo . TryGetValue ( cmd , out var cmdInfo )
79
- ? cmdInfo : garnetCommandsInfo [ cmd ] ;
86
+ var inQueried = queriedCommandsInfo . TryGetValue ( cmd , out var queriedCommandInfo ) ;
87
+ var inGarnet = garnetCommandsInfo . TryGetValue ( cmd , out var garnetCommandInfo ) ;
88
+ var baseCommandInfo = inGarnet ? garnetCommandInfo : queriedCommandInfo ;
80
89
81
90
RespCommandsInfo [ ] subCommandsInfo ;
82
- if ( garnetCommandsInfo . ContainsKey ( cmd ) && queriedCommandsInfo . ContainsKey ( cmd ) )
91
+ if ( inQueried && inGarnet )
83
92
{
84
93
var subCommandsInfoMap = new Dictionary < string , RespCommandsInfo > ( ) ;
85
94
86
- if ( garnetCommandsInfo . TryGetValue ( cmd , out var garnetCmdInfo ) && garnetCmdInfo . SubCommands != null )
95
+ if ( garnetCommandInfo . SubCommands != null )
87
96
{
88
- foreach ( var sc in garnetCmdInfo . SubCommands )
97
+ foreach ( var sc in garnetCommandInfo . SubCommands )
89
98
subCommandsInfoMap . Add ( sc . Name , sc ) ;
90
99
}
91
100
92
- if ( queriedCommandsInfo . TryGetValue ( cmd , out var queriedCmdInfo ) && queriedCmdInfo . SubCommands != null )
101
+ if ( queriedCommandInfo . SubCommands != null )
93
102
{
94
- foreach ( var sc in queriedCmdInfo . SubCommands )
103
+ foreach ( var sc in queriedCommandInfo . SubCommands )
95
104
{
96
105
subCommandsInfoMap . TryAdd ( sc . Name , sc ) ;
97
106
}
@@ -104,7 +113,7 @@ public static bool TryUpdateCommandInfo(string outputDir, int respServerPort, IP
104
113
subCommandsInfo = baseCommandInfo . SubCommands ;
105
114
}
106
115
107
- additionalCommandsInfo . Add ( cmd , new RespCommandsInfo ( )
116
+ additionalCommandsInfo . Add ( cmd , new RespCommandsInfo
108
117
{
109
118
Command = baseCommandInfo . Command ,
110
119
Name = baseCommandInfo . Name ,
@@ -117,7 +126,7 @@ public static bool TryUpdateCommandInfo(string outputDir, int respServerPort, IP
117
126
AclCategories = baseCommandInfo . AclCategories ,
118
127
Tips = baseCommandInfo . Tips ,
119
128
KeySpecifications = baseCommandInfo . KeySpecifications ,
120
- SubCommands = subCommandsInfo
129
+ SubCommands = subCommandsInfo ? . OrderBy ( sc => sc . Name ) . ToArray ( )
121
130
} ) ;
122
131
}
123
132
}
@@ -147,10 +156,8 @@ public static bool TryUpdateCommandInfo(string outputDir, int respServerPort, IP
147
156
/// <param name="commandsInfo">Queried commands info</param>
148
157
/// <returns>True if succeeded</returns>
149
158
private static unsafe bool TryGetCommandsInfo ( string [ ] commandsToQuery , int respServerPort ,
150
- IPAddress respServerHost , ILogger logger , out IDictionary < string , RespCommandsInfo > commandsInfo )
159
+ IPAddress respServerHost , ILogger logger , ref IDictionary < string , RespCommandsInfo > commandsInfo )
151
160
{
152
- commandsInfo = default ;
153
-
154
161
// If there are no commands to query, return
155
162
if ( commandsToQuery . Length == 0 ) return true ;
156
163
@@ -167,8 +174,6 @@ private static unsafe bool TryGetCommandsInfo(string[] commandsToQuery, int resp
167
174
return false ;
168
175
}
169
176
170
- var tmpCommandsInfo = new Dictionary < string , RespCommandsInfo > ( ) ;
171
-
172
177
// Get a map of supported commands to Garnet's RespCommand & ArrayCommand for the parser
173
178
var supportedCommands = new ReadOnlyDictionary < string , RespCommand > (
174
179
SupportedCommand . SupportedCommandsFlattenedMap . ToDictionary ( kvp => kvp . Key ,
@@ -197,11 +202,10 @@ private static unsafe bool TryGetCommandsInfo(string[] commandsToQuery, int resp
197
202
}
198
203
199
204
if ( command != null )
200
- tmpCommandsInfo . Add ( command . Name , command ) ;
205
+ commandsInfo . Add ( command . Name , command ) ;
201
206
}
202
207
}
203
208
204
- commandsInfo = tmpCommandsInfo ;
205
209
return true ;
206
210
}
207
211
@@ -238,7 +242,7 @@ private static IReadOnlyDictionary<string, RespCommandsInfo> GetUpdatedCommandsI
238
242
: existingCommandsInfo [ command . Command ] . SubCommands . Select ( sc => sc . Name ) . ToArray ( ) ;
239
243
var remainingSubCommands = existingSubCommands == null ? null :
240
244
command . SubCommands == null ? existingSubCommands :
241
- existingSubCommands . Except ( command . SubCommands . Keys ) . ToArray ( ) ;
245
+ [ .. existingSubCommands . Except ( command . SubCommands . Keys ) ] ;
242
246
243
247
// Create updated command info based on existing command
244
248
var existingCommand = existingCommandsInfo [ command . Command ] ;
@@ -257,7 +261,7 @@ private static IReadOnlyDictionary<string, RespCommandsInfo> GetUpdatedCommandsI
257
261
KeySpecifications = existingCommand . KeySpecifications ,
258
262
SubCommands = remainingSubCommands == null || remainingSubCommands . Length == 0
259
263
? null
260
- : existingCommand . SubCommands . Where ( sc => remainingSubCommands . Contains ( sc . Name ) ) . ToArray ( )
264
+ : [ .. existingCommand . SubCommands . Where ( sc => remainingSubCommands . Contains ( sc . Name ) ) ]
261
265
} ;
262
266
263
267
updatedCommandsInfo . Add ( updatedCommand . Name , updatedCommand ) ;
@@ -294,7 +298,7 @@ private static IReadOnlyDictionary<string, RespCommandsInfo> GetUpdatedCommandsI
294
298
// Update sub-commands to contain supported sub-commands only
295
299
updatedSubCommands = command . SubCommands == null
296
300
? null
297
- : baseCommand . SubCommands . Where ( sc => command . SubCommands . ContainsKey ( sc . Name ) ) . ToList ( ) ;
301
+ : [ .. baseCommand . SubCommands . Where ( sc => command . SubCommands . ContainsKey ( sc . Name ) ) ] ;
298
302
}
299
303
300
304
// Create updated command info based on base command & updated sub-commands
0 commit comments