VictoriaMetrics/lib/mergeset
Aliaksandr Valialkin 43b24164ef
all: add Windows build for VictoriaMetrics
This commit changes background merge algorithm, so it becomes compatible with Windows file semantics.

The previous algorithm for background merge:

1. Merge source parts into a destination part inside tmp directory.
2. Create a file in txn directory with instructions on how to atomically
   swap source parts with the destination part.
3. Perform instructions from the file.
4. Delete the file with instructions.

This algorithm guarantees that either source parts or destination part
is visible in the partition after unclean shutdown at any step above,
since the remaining files with instructions is replayed on the next restart,
after that the remaining contents of the tmp directory is deleted.

Unfortunately this algorithm doesn't work under Windows because
it disallows removing and moving files, which are in use.

So the new algorithm for background merge has been implemented:

1. Merge source parts into a destination part inside the partition directory itself.
   E.g. now the partition directory may contain both complete and incomplete parts.
2. Atomically update the parts.json file with the new list of parts after the merge,
   e.g. remove the source parts from the list and add the destination part to the list
   before storing it to parts.json file.
3. Remove the source parts from disk when they are no longer used.

This algorithm guarantees that either source parts or destination part
is visible in the partition after unclean shutdown at any step above,
since incomplete partitions from step 1 or old source parts from step 3 are removed
on the next startup by inspecting parts.json file.

This algorithm should work under Windows, since it doesn't remove or move files in use.
This algorithm has also the following benefits:

- It should work better for NFS.
- It fits object storage semantics.

The new algorithm changes data storage format, so it is impossible to downgrade
to the previous versions of VictoriaMetrics after upgrading to this algorithm.

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3236
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3821
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/70
2023-03-19 01:36:51 -07:00
..
block_header.go lib/mergeset: properly reset bsr.bhIdx after the call to blockStreamReader.readNextBHS() 2022-11-16 21:23:35 +02:00
block_stream_reader.go all: add Windows build for VictoriaMetrics 2023-03-19 01:36:51 -07:00
block_stream_reader_test.go lib/mergeset: use deterministic random generator in tests 2023-01-23 19:43:49 -08:00
block_stream_writer.go lib/{mergeset,storage}: pass compressLevel to blockStreamWriter.InitFromInmemoryPart 2022-12-03 22:46:48 -08:00
encoding.go app,lib: fix typos in comments (#3804) 2023-02-13 13:27:13 +01:00
encoding_test.go lib/mergeset: use deterministic random generator in tests 2023-01-23 19:43:49 -08:00
encoding_timing_test.go lib/mergeset: fix data race in BenchmarkInmemoryBlockMarshal 2023-01-23 19:43:18 -08:00
inmemory_part.go all: add -inmemoryDataFlushInterval command-line flag for controlling the frequency of saving in-memory data to disk 2022-12-05 15:16:14 -08:00
merge.go lib/mergeset: do not update blockStreamReader.bh.firstItem during the merge 2022-07-27 23:05:02 +03:00
merge_test.go lib/mergeset: use deterministic random generator in tests 2023-01-23 19:43:49 -08:00
metaindex_row.go all: subsitute ioutil.ReadAll with io.ReadAll 2022-08-22 00:16:37 +03:00
part.go all: add Windows build for VictoriaMetrics 2023-03-19 01:36:51 -07:00
part_header.go all: add Windows build for VictoriaMetrics 2023-03-19 01:36:51 -07:00
part_search.go lib/mergeset: retain the buffer with the data used by indexBlock.bhs, inside indexBlock.buf 2022-11-16 12:09:23 +02:00
part_search_test.go lib/mergeset: use deterministic random generator in tests 2023-01-23 19:43:49 -08:00
table.go all: add Windows build for VictoriaMetrics 2023-03-19 01:36:51 -07:00
table_search.go optimized code (#2103) 2022-01-28 14:15:41 +02:00
table_search_test.go lib/mergeset: use deterministic random generator in tests 2023-01-23 19:43:49 -08:00
table_search_timing_test.go lib/mergeset: use deterministic random generator in tests 2023-01-23 19:43:49 -08:00
table_test.go lib/storage: enhancements for snapshots process (#3873) 2023-02-27 12:12:03 -08:00