git/reftable/writer.h
John Cai 1df18a1c9a reftable: honor core.fsync
While the reffiles backend honors configured fsync settings, the
reftable backend does not. Address this by fsyncing reftable files using
the write-or-die api's fsync_component() in two places: when we
add additional entries into the table, and when we close the reftable
writer.

This commits adds a flush function pointer as a new member of
reftable_writer because we are not sure that the first argument to the
*write function pointer always contains a file descriptor. In the case of
strbuf_add_void, the first argument is a buffer. This way, we can pass
in a corresponding flush function that knows how to flush depending on
which writer is being used.

This patch does not contain tests as they will need to wait for another
patch to start to exercise the reftable backend. At that point, the
tests will be added to observe that fsyncs are happening when the
reftable is in use.

Signed-off-by: John Cai <johncai86@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-01-23 13:45:27 -08:00

52 lines
1.1 KiB
C

/*
Copyright 2020 Google LLC
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file or at
https://developers.google.com/open-source/licenses/bsd
*/
#ifndef WRITER_H
#define WRITER_H
#include "basics.h"
#include "block.h"
#include "tree.h"
#include "reftable-writer.h"
struct reftable_writer {
ssize_t (*write)(void *, const void *, size_t);
int (*flush)(void *);
void *write_arg;
int pending_padding;
struct strbuf last_key;
/* offset of next block to write. */
uint64_t next;
uint64_t min_update_index, max_update_index;
struct reftable_write_options opts;
/* memory buffer for writing */
uint8_t *block;
/* writer for the current section. NULL or points to
* block_writer_data */
struct block_writer *block_writer;
struct block_writer block_writer_data;
/* pending index records for the current section */
struct reftable_index_record *index;
size_t index_len;
size_t index_cap;
/*
* tree for use with tsearch; used to populate the 'o' inverse OID
* map */
struct tree_node *obj_index_tree;
struct reftable_stats stats;
};
#endif