Skip to contents

Commit, amend, flush, discard, rebase

Usage

ic_commit(session, message, metadata = NULL, allow_empty = FALSE)

ic_amend(session, message, metadata = NULL)

ic_flush(session, message, metadata = NULL)

ic_discard(session)

ic_rebase(
  session,
  solver = c("detect", "basic"),
  on_chunk = c("ours", "theirs", "fail")
)

ic_status(session)

Arguments

session

a writable icechunk_session.

message

commit message.

metadata

a named list stored with the snapshot.

allow_empty

commit even with no changes.

solver

"detect" fails on any conflict; "basic" resolves chunk conflicts by on_chunk.

on_chunk

for solver = "basic": "ours", "theirs" or "fail".

Value

new snapshot id (commit/amend/flush).

Details

A commit that loses a race raises a condition of class icechunk_conflict; call ic_rebase() and commit again.

Examples

ex <- ic_example_repo()
repo <- ic_repo_open(ex$path, authorize = ex$authorize)
s <- ic_session_writable(repo, "main")
ic_set(s, "zarr.json", charToRaw('{"zarr_format":3,"node_type":"group","attributes":{"v":2}}'))
ic_status(s)
#> <icechunk_diff>
#>   updated_groups: /
id <- ic_commit(s, "attributes, take one", metadata = list(author = "example"))
ic_session_info(s)$read_only     # a committed session is done
#> [1] TRUE

# replace that commit instead of adding another
s <- ic_session_writable(repo, "main")
ic_set(s, "zarr.json", charToRaw('{"zarr_format":3,"node_type":"group","attributes":{"v":3}}'))
ic_amend(s, "attributes, take two")
#> [1] "88XYXDHY22HCF6AD1SJG"
ic_ancestry(repo, branch = "main")$message[1:2]
#> [1] "attributes, take two" "a small array"       

# two writers: the second commit conflicts, rebase onto the new head
a <- ic_session_writable(repo, "main")
b <- ic_session_writable(repo, "main")
ic_set(a, "small/c/0/0", writeBin(as.double(1:6), raw(), size = 8, endian = "little"))
ic_set(b, "small/c/1/1", writeBin(as.double(7:12), raw(), size = 8, endian = "little"))
ic_commit(a, "writer a")
#> [1] "Q7NPA43BZHC7P0GGZERG"
res <- tryCatch(ic_commit(b, "writer b"), icechunk_conflict = function(e) e)
class(res)
#> [1] "icechunk_conflict" "icechunk_error"    "error"            
#> [4] "condition"        
ic_rebase(b)
ic_commit(b, "writer b, rebased")
#> [1] "24DTDT4CR7Q4ZT1QAB2G"