GizStack
View .mdOpen in ChatGPTOpen in Claude

gizmodel/copy

The pieces every copy into GizDB shares: the page credit, the rows a source answers, and the one proof of a copy, an order-free checksum of its rows (Store.copy and Store.move, gizdb migrate). Federation's model/source.giz owns query planning, not data movement.

gizlang
import * as Copy from "gizmodel/copy";

Types

Column

gizlang
type Column = { slot: Slot; declared: string; }

Preserve the declared type; a text slot cannot identify JSON by itself.

  • slot: M142.Slot
  • declared: string

Rows

gizlang
type Rows = { columns: Vec<Column>; rows: Vec<Vec<Value>>; }

The columns and the rows of one page of a copy.

  • columns: Vec<M126.Column>
  • rows: Vec<Vec<M143.Value>>

Copy

gizlang
type Copy = { table: string; rows: i64; bytes: i64; done: bool; }

The state of the copy of one table: rows and bytes copied, and whether it is done.

  • table: string
  • rows: i64
  • bytes: i64
  • done: bool

Verification

gizlang
type Verification = { table: string; status: string; source: Checksum; target: Checksum; firstKey: string; bytes: i64; }

The check of one copied table: its status, the checksums of source and target, and the first key that differs.

  • table: string
  • status: string
  • source: M126.Checksum
  • target: M126.Checksum
  • firstKey: string
  • bytes: i64

Progress

gizlang
type Progress = { source: string; table: string; lastKey: string; offset: i64; done: bool; rows: i64; bytes: i64; schema: string; }

Where the copy of one table stands: the last key and offset copied, the rows and bytes so far, and its schema.

  • source: string
  • table: string
  • lastKey: string
  • offset: i64
  • done: bool
  • rows: i64
  • bytes: i64
  • schema: string

Checksum

gizlang
type Checksum = { count: i64; sum: bytes; }

The proof of a copy: the SHA-256 digests of its rows summed modulo 2^256, and their count. The order of the rows does not change it, so a source and a target that order keys apart, and pages copied in any order, compare equal.

  • count: i64
  • sum: bytes

Functions

checksum

gizlang
function checksum(): Checksum

An empty checksum: no rows, a zero sum.

Effects: fail, alloc.

contentDigest

gizlang
function contentDigest(row: Vec<Value>): bytes throws DbError

The SHA-256 digest of the encoded ROW. A row over 8 MiB is refused.

Effects: fail, alloc.

Methods

Checksum.add

gizlang
function Checksum.add(self: mut Checksum, row: Vec<Value>): bool throws DbError

Adds the digest of ROW to the checksum.

Effects: fail, alloc.

Checksum.include

gizlang
function Checksum.include(self: mut Checksum, other: Checksum): bool throws DbError

Adds the rows that OTHER counts.

Effects: fail, alloc.

Constants

TARGET_PAGE_BYTES

gizlang
const TARGET_PAGE_BYTES: i64 = 262144

Page credit fits the native actor. It does not limit the complete result.

MAX_PAGE_ROWS

gizlang
const MAX_PAGE_ROWS: i64 = 1000

The most rows in one page of a copy.