Blyx Nest Blyx language
Registry / Framework
framework · v0.1.2

Compaction Swap

Retain old table segments until the replacement file has the expected record count and readers drain.

Source repository · Package JSON

Use Compaction Swap

use vendor::compaction_swap::compaction_swap;

Run the example

nest demo compaction_swap@0.1.2
blyxc native-run compaction_swap-demo/main.blyx
Example source and expected output
use std::cli;
use std::text;
use vendor::compaction_swap::compaction_swap;

fn main() {
    let arguments = cli_args();
    if args_len(arguments) > 0 {
        if args_len(arguments) % 2 != 0 {
            stderr_line("Expected event and value pairs");
            process_exit(2);
        }
        let mut live = compaction_swap_start();
        let mut i = 0;
        while i < args_len(arguments) {
            let input = args_at(arguments, i + 1);
            if !text_is_number(input) {
                stderr_line("Expected a whole numeric event value");
                process_exit(2);
            }
            live = compaction_swap_step(live, args_at(arguments, i), text_number(input));
            let command = compaction_swap_command(live);
            println!(command);
            if command == "reject" { process_exit(1); }
            i += 2;
        }
        return;
    }
    let mut state = compaction_swap_start();
    state = compaction_swap_step(state, "plan", 9.0);
    println!(compaction_swap_command(state));
    state = compaction_swap_step(state, "finish", 9.0);
    println!(compaction_swap_command(state));
    state = compaction_swap_step(state, "readers", 2.0);
    println!(compaction_swap_command(state));
    state = compaction_swap_step(state, "readers", 0.0);
    println!(compaction_swap_command(state));
}

Expected output

write_segment
swap_segment
wait_readers
unlink_old

Published versions

VersionPackageSource commitSHA-256
0.1.2Download ZIP · Browse files13a91f6ff4729ab057c0a20648e820c302e8788c476753667572b8218ae95dec3067047e26
0.1.1Download ZIP · Browse files79c11714dd227716b31a3bf476148bae63ee1654032f3ee979c68c5bd56f9d423be4d4a519
0.1.0Download ZIP · Browse files6349f237843a33bb8215cd7f8d365062a7a70891630bb9a09766617642f3441d3eb467aec3