Debian Codegraph @

doc/source/reference/commands/io_flush.rst

raw
1 .. -*- rst -*-
2
3 .. groonga-command
4 .. database: commands_io_flush
5
6 ``io_flush``
7 ============
8
9 Summary
10 -------
11
12 .. versionadded:: 5.0.5
13
14 ``io_flush`` flushes all changes in memory to disk
15 explicitly. Normally, you don't need to use ``io_flush``
16 explicitly. Because flushing is done automatically by OS. And flushing
17 by OS is effective.
18
19 You need to use ``io_flush`` explicitly when your system may often
20 crash unexpectedly or you may not shutdown your Groonga process in a
21 normal way. (For example, using :doc:`shutdown` is a normal shutdown
22 process.) It's better that you use ``io_flush`` after you change your
23 Groonga database for the case. Here are commands that change your
24 Groonga database:
25
26 * :doc:`column_create`
27 * :doc:`column_remove`
28 * :doc:`column_rename`
29 * :doc:`delete`
30 * :doc:`load`
31 * :doc:`logical_table_remove`
32 * :doc:`object_remove`
33 * :doc:`plugin_register`
34 * :doc:`plugin_unregister`
35 * :doc:`table_create`
36 * :doc:`table_remove`
37 * :doc:`table_rename`
38 * :doc:`truncate`
39
40 If you're using :ref:`select-scorer` parameter in :doc:`select` to
41 change existing column values, :doc:`select` is added to the above
42 list.
43
44 Note that ``io_flush`` may be a heavy process. If there are many
45 changes in memory, flushing them to disk is a heavy process.
46
47 .. versionadded:: 8.0.8
48
49 ``io_flush`` locks Groonga database while flushing. It means that
50 you can't run the following commands while ``io_flush``:
51
52 * :doc:`column_create`
53 * :doc:`column_remove`
54 * :doc:`column_rename`
55 * :doc:`logical_table_remove`
56 * :doc:`object_remove`
57 * :doc:`plugin_register`
58 * :doc:`plugin_unregister`
59 * :doc:`table_create`
60 * :doc:`table_remove`
61 * :doc:`table_rename`
62
63 Syntax
64 ------
65
66 This command takes three parameters.
67
68 All parameters are optional::
69
70 io_flush [target_name=null]
71 [recursive=yes]
72 [only_opened=no]
73
74 .. versionadded:: 7.0.4
75
76 :ref:`io-flush-only-opened` is added.
77
78 .. versionadded:: 9.0.2
79
80 ``--recursive dependent`` option is added. It is recommended way to flush
81 target object and its related objects since 9.0.2. See :ref:`io-flush-recursive` about details.
82
83 Usage
84 -----
85
86 You can flush all changes in memory to disk with no arguments:
87
88 .. groonga-command
89 .. include:: ../../example/reference/commands/io_flush/all.log
90 .. io_flush
91
92 If you know what is changed, you can narrow flush targets. Here is a
93 correspondence table between command and flush targets for Groonga 9.0.2 or later.
94
95 .. note:: There is a different recommended way which depends on Groonga version.
96 If Groonga is 9.0.1 or earlier ( ``--recursive dependent`` is not available ), you
97 need to flush related objects explicitly, otherwise, using ``--recursive dependent``
98 is a recommended way not to forget flush target objects.
99
100 .. list-table::
101 :header-rows: 1
102
103 * - Command
104 - Flush targets
105 - ``io_flush`` arguments
106 * - :doc:`load` and :doc:`delete`
107 - Target table and its columns.
108
109 If there are one or more reference columns in these columns,
110 referenced tables are also flush targets.
111
112 If there are one or more indexed columns in these columns,
113 tables of corresponding index columns and corresponding index
114 columns are also flush targets.
115
116 - Use ``--recursive dependent`` to flush target table and
117 its columns, referenced tables and tables of corresponding index columns
118 and corresponding index columns at once::
119
120 io_flush --target_name TABLE_NAME --recursive dependent
121
122 * - :doc:`truncate`
123 - Target table and its columns.
124
125 If there are one or more reference columns in these columns,
126 referenced tables are also flush targets.
127
128 If there are one or more indexed columns in these columns,
129 tables of corresponding index columns and corresponding index
130 columns are also flush targets.
131
132 Database is also flush target.
133
134 - Use ``--recursive dependent`` to flush target table and its columns,
135 referenced tables and tables of corresponding index columns and corresponding index
136 columns at once::
137
138 io_flush --target_name TABLE_NAME --recursive dependent
139
140 * - :doc:`table_create`
141 - Target table and database.
142 - Table::
143
144 io_flush --target_name TABLE_NAME --recursive dependent
145
146 * - :doc:`table_remove`, :doc:`table_rename` and :doc:`logical_table_remove`
147 - Database.
148 - Database::
149
150 io_flush --recursive no
151 * - :doc:`column_create`
152 - Target column and database.
153 - Table::
154
155 io_flush --target_name TABLE_NAME.COLUMN_NAME --recursive dependent
156 * - :doc:`column_remove` and :doc:`column_rename`
157 - Database.
158 - Database::
159
160 io_flush --recursive no
161 * - :doc:`plugin_register` and :doc:`plugin_unregister`
162 - Database.
163 - Database::
164
165 io_flush --recursive no
166
167 If Groonga is 9.0.1 or earlier ( ``--recursive dependent`` is not available ), flush
168 objects explicitly. Here is a correspondence table between command and flush targets
169 for Groonga 9.0.1 or earlier.
170
171 .. list-table::
172 :header-rows: 1
173
174 * - Command
175 - Flush targets
176 - ``io_flush`` arguments
177 * - :doc:`load` and :doc:`delete`
178 - Target table and its columns.
179
180 If there are one or more reference columns in these columns,
181 referenced tables are also flush targets.
182
183 If there are one or more indexed columns in these columns,
184 tables of corresponding index columns and corresponding index
185 columns are also flush targets.
186 - Table and its columns::
187
188 io_flush --target_name TABLE_NAME
189
190 A referenced table::
191
192 io_flush --target_name REFERENCED_TABLE_NAME --recursive no
193
194 A table of an index column::
195
196 io_flush --target_name TABLE_NAME_OF_INDEX_COLUMN --recursive no
197
198 An index column::
199
200 io_flush --target_name TABLE_NAME_OF_INDEX_COLUMN.INDEX_COLUMN
201 * - :doc:`truncate`
202 - Target table and its columns.
203
204 If there are one or more reference columns in these columns,
205 referenced tables are also flush targets.
206
207 If there are one or more indexed columns in these columns,
208 tables of corresponding index columns and corresponding index
209 columns are also flush targets.
210
211 Database is also flush target.
212 - Table and its columns::
213
214 io_flush --target_name TABLE_NAME
215
216 A referenced table::
217
218 io_flush --target_name REFERENCED_TABLE_NAME --recursive no
219
220 A table of an index column::
221
222 io_flush --target_name TABLE_NAME_OF_INDEX_COLUMN --recursive no
223
224 An index column::
225
226 io_flush --target_name TABLE_NAME_OF_INDEX_COLUMN.INDEX_COLUMN
227
228 Database::
229
230 io_flush --recursive no
231 * - :doc:`table_create`
232 - Target table and database.
233 - Table::
234
235 io_flush --target_name TABLE_NAME
236
237 Database::
238
239 io_flush --recursive no
240 * - :doc:`table_remove`, :doc:`table_rename` and :doc:`logical_table_remove`
241 - Database.
242 - Database::
243
244 io_flush --recursive no
245 * - :doc:`column_create`
246 - Target column and database.
247 - Table::
248
249 io_flush --target_name TABLE_NAME.COLUMN_NAME
250
251 Database::
252
253 io_flush --recursive no
254 * - :doc:`column_remove` and :doc:`column_rename`
255 - Database.
256 - Database::
257
258 io_flush --recursive no
259 * - :doc:`plugin_register` and :doc:`plugin_unregister`
260 - Database.
261 - Database::
262
263 io_flush --recursive no
264
265
266 Parameters
267 ----------
268
269 This section describes all parameters.
270
271 Required parameters
272 ^^^^^^^^^^^^^^^^^^^
273
274 There is no required parameter.
275
276 Optional parameters
277 ^^^^^^^^^^^^^^^^^^^
278
279 There are optional parameters.
280
281 .. _io-flush-target-name:
282
283 ``target_name``
284 """""""""""""""
285
286 Specifies a target object name. Target object is one of database,
287 table or column.
288
289 If you omit this parameter, database is the target object:
290
291 .. groonga-command
292 .. include:: ../../example/reference/commands/io_flush/target_name_database.log
293 .. io_flush
294
295 If you specify a table name, the table is the target object:
296
297 .. groonga-command
298 .. include:: ../../example/reference/commands/io_flush/target_name_table.log
299 .. table_create Users TABLE_HASH_KEY ShortText
300 .. io_flush --target_name Users
301
302 If you specify a column name, the column is the target object:
303
304 .. groonga-command
305 .. include:: ../../example/reference/commands/io_flush/target_name_column.log
306 .. column_create Users age COLUMN_SCALAR UInt8
307 .. io_flush --target_name Users.age
308
309 .. _io-flush-recursive:
310
311 ``recursive``
312 """""""""""""
313
314 Specifies whether child objects of the target object are also target
315 objects.
316
317 Child objects of database are all tables and all columns.
318
319 Child objects of table are all its columns.
320
321 Child objects of column are nothing.
322
323 If you specify ``yes`` to :ref:`io-flush-only-opened`, ``recursive``
324 is ignored.
325
326 ``recursive`` value must be ``yes``, ``no`` or ``dependent``. ``yes``
327 means that all of the specified target object and child objects are
328 the target objects. ``no`` means that only the specified target object
329 is the target object. ``dependent`` means that all of the specified
330 target object, child objects, corresponding table of index column and
331 corresponding index column are the target objects.
332
333 The following ``io_flush`` flushes all changes in database, all tables
334 and all columns:
335
336 .. groonga-command
337 .. include:: ../../example/reference/commands/io_flush/recursive_yes.log
338 .. io_flush --recursive yes
339
340 The following ``io_flush`` flushes all changes only in database:
341
342 .. groonga-command
343 .. include:: ../../example/reference/commands/io_flush/recursive_no.log
344 .. io_flush --recursive no
345
346 If you specify other value (not ``yes`` neither ``no``) or omit
347 ``recursive`` parameter, ``yes`` is used.
348
349 ``yes`` is used in the following case because invalid ``recursive``
350 argument is specified:
351
352 .. groonga-command
353 .. include:: ../../example/reference/commands/io_flush/recursive_invalid.log
354 .. io_flush --recursive invalid
355
356 ``yes`` is used in the following case because ``recursive`` parameter
357 isn't specified:
358
359 .. groonga-command
360 .. include:: ../../example/reference/commands/io_flush/recursive_default.log
361 .. io_flush
362
363 Since 9.0.2, ``--recursive dependent`` is added to flush not only target object
364 and child objects, but also related objects. The related objects are:
365
366 * A referenced table
367 * A related index column (There is source column in target ``TABLE_NAME``)
368 * A table of related index column (There is source column in target ``TABLE_NAME``)
369
370 It is useful not to forget flushing related objects.
371
372 For example, ``--recursive dependent`` is specified for ``TABLE_NAME``, this
373 option executes equivalent to the following commands internally.
374
375 - Flush table and its columns::
376
377 io_flush --target_name TABLE_NAME --recursive yes
378
379 - Flush a referenced table::
380
381 io_flush --target_name REFERENCED_TABLE_NAME --recursive no
382
383 - Flush a related index column (There is source column in ``TABLE_NAME``)::
384
385 io_flush --target_name TABLE_NAME_OF_INDEX_COLUMN.INDEX_COLUMN
386
387 - Flush a table of related index column (There is source column in ``TABLE_NAME``)::
388
389 io_flush --target_name TABLE_NAME_OF_INDEX_COLUMN --recursive no
390
391 To confirm whether all target objects are flushed correctly, you can check query log::
392
393 > io_flush --recursive "dependent" --target_name "Users"
394 :000000000000000 flush[Users]
395 :000000000000000 flush[Terms]
396 :000000000000000 flush[Terms.users_name]
397 :000000000000000 flush[Users.name]
398 :000000000000000 flush[(anonymous:table:dat_key)]
399 :000000000000000 flush[(anonymous:column:var_size)]
400 :000000000000000 flush[(anonymous:table:hash_key)]
401 :000000000000000 flush[(anonymous:column:var_size)]
402 :000000000000000 flush[(DB)]
403 <000000000000000 rc=0
404
405 In above example, specified not only ``Users`` table, related lexicon table ``Terms`` and
406 index column ``Terms.users_name`` (data source is ``Users.name``) are also flushed.
407
408 ``flush[(anonymous:...)]`` and ``flush[(DB)]`` means that Groonga's internal objects
409 are also flushed.
410
411 .. list-table::
412 :header-rows: 1
413
414 * - Log
415 - Description
416
417 * - ``flush[(anonymous:table:dat_key)]``
418 - The internal object names in DB are flushed. If ``GRN_DB_KEY=pat`` is set, ``TABLE_PAT_KEY`` is used instead.
419
420 * - ``flush[(anonymous:column:var_size)]`` (logged as first ``(anonymous:column:var_size)`` object)
421 - The internal object metadata (builtin types, token filter and so on) are flushed.
422
423 This is a variable sized column which stores the above internal object metadata.
424
425 * - ``flush[(anonymous:table:hash_key)]``
426
427 - The internal configuration objects (which is set by ``config_set``) are flushed.
428
429 * - ``flush[(anonymous:column:var_size)]`` (logged as second ``(anonymous:column:var_size)`` object)
430 - The internal object metadata (options about internal objects such as specified tokenizer options) are flushed.
431
432 This is a variable sized column which stores the above internal object metadata.
433
434 * - ``flush[(DB)]``
435
436 - The DB changes (lock acquired during ``io_flush``) are flushed.
437
438 .. _io-flush-only-opened:
439
440 ``only_opened``
441 """""""""""""""
442
443 .. versionadded:: 7.0.4
444
445 Specifies whether opened objects are only flushed.
446
447 If there is only one process that changes the target database, flush
448 performance will be improved by specifying ``yes`` to
449 ``only_opened``. It skips needless flushes.
450
451 You can't specify :ref:`io-flush-target-name` with ``only_opened``
452 option. If you specify :ref:`io-flush-target-name`, ``only_opened`` is
453 ignored.
454
455 If you specify ``yes`` to ``only_opened``, :ref:`io-flush-recursive`
456 is ignored.
457
458 ``only_opened`` value must be ``yes`` or ``no``. ``yes`` means that
459 opened objects are only flushed. ``no`` means that all target objects
460 are flushed even they aren't opened.
461
462 The following ``io_flush`` flushes all changes in database, all tables
463 and all columns:
464
465 .. groonga-command
466 .. include:: ../../example/reference/commands/io_flush/only_opened_yes.log
467 .. io_flush --only_opened yes
468
469 Return value
470 ------------
471
472 The command returns ``true`` as body on success such as::
473
474 [HEADER, true]
475
476 If the command fails, error details are in ``HEADER``.
477
478 See :doc:`/reference/command/output_format` for ``HEADER``.