4141
4242_ENABLE_COLUMNAR_RECOMMENDATION = flags .DEFINE_bool (
4343 'alloydb_enable_columnar_recommendation' ,
44- False ,
44+ None ,
4545 'Set alloydb_enable_columnar_recommendation to On if true.' ,
4646)
4747
48+ _ENABLE_INDEX_CACHING = flags .DEFINE_bool (
49+ 'alloydb_enable_index_caching' ,
50+ False ,
51+ 'Set alloydb_enable_index_caching to On if true.' ,
52+ )
4853
4954_READ_POOL_NODE_COUNT = flags .DEFINE_integer (
5055 'alloydb_read_pool_node_count' ,
@@ -251,11 +256,14 @@ def _PostCreate(self) -> None:
251256 columnar_engine_size = None
252257 if _COLUMNAR_ENGINE .value :
253258 columnar_engine_size = _COLUMNAR_ENGINE_SIZE .value
254- self .UpdateAlloyDBFlags (
259+ updated = self .UpdateAlloyDBFlags (
255260 columnar_engine_size ,
256261 _ENABLE_COLUMNAR_RECOMMENDATION .value ,
257262 _ENABLE_AUTO_COLUMNARIZATION .value ,
263+ enable_index_caching = _ENABLE_INDEX_CACHING .value ,
258264 )
265+ if updated :
266+ self .RestartInstance ()
259267 self ._UpdateLabels (util .GetDefaultTags ())
260268
261269 def _DescribeCluster (self ) -> Dict [str , Any ]:
@@ -329,11 +337,31 @@ def WaitColumnarEnginePopulates(self, database_name: str):
329337 def UpdateAlloyDBFlags (
330338 self ,
331339 columnar_engine_size : int | None ,
332- enable_columnar_recommendation : bool ,
340+ enable_columnar_recommendation : bool | None ,
333341 enable_auto_columnarization : str ,
342+ enable_index_caching : bool = False ,
334343 relation : str | None = None ,
335- ):
344+ ) -> bool :
345+ """Update flags on an existing AlloyDB instance.
346+
347+ See https://docs.cloud.google.com/alloydb/docs/reference/database-flags for
348+ information on individual flags.
349+
350+ Args:
351+ columnar_engine_size: Set google_columnar_engine.memory_size_in_mb.
352+ enable_columnar_recommendation: Set
353+ google_columnar_engine.enable_columnar_recommendation.
354+ enable_auto_columnarization: Set
355+ google_columnar_engine.enable_auto_columnarization.
356+ enable_index_caching: Set google_columnar_engine.enable_index_caching.
357+ relation: Set google_columnar_engine.relations.
358+
359+ Returns:
360+ True if flags were updated, False otherwise.
361+ """
362+
336363 database_flags = []
364+ flags_updated = False
337365 if FLAGS .db_flags :
338366 database_flags += [':' .join (FLAGS .db_flags )]
339367
@@ -347,9 +375,14 @@ def UpdateAlloyDBFlags(
347375 ),
348376 ]
349377
350- if enable_columnar_recommendation :
378+ if enable_columnar_recommendation is not None :
379+ database_flags += [
380+ f'google_columnar_engine.enable_columnar_recommendation={
381+ "on" if enable_columnar_recommendation else "off" } '
382+ ]
383+ if enable_index_caching :
351384 database_flags += [
352- 'google_columnar_engine.enable_columnar_recommendation =on' ,
385+ 'google_columnar_engine.enable_index_caching =on' ,
353386 ]
354387 if relation :
355388 database_flags += [f'google_columnar_engine.relations={ relation } ' ]
@@ -365,6 +398,19 @@ def UpdateAlloyDBFlags(
365398 ]
366399 cmd = self ._GetAlloyDbCommand (cmd_string )
367400 cmd .Issue (timeout = CREATION_TIMEOUT )
401+ flags_updated = True
402+ return flags_updated
403+
404+ def RestartInstance (self ):
405+ cmd_string = [
406+ 'instances' ,
407+ 'restart' ,
408+ self .instance_id ,
409+ f'--cluster={ self .cluster_id } ' ,
410+ '--no-async' ,
411+ ]
412+ cmd = self ._GetAlloyDbCommand (cmd_string )
413+ cmd .Issue (timeout = CREATION_TIMEOUT )
368414
369415 def GetColumnarEngineRecommendation (
370416 self , database_name : str
0 commit comments