MCPcopy
hub / github.com/benbjohnson/litestream / OpenLTXFile

Method OpenLTXFile

oss/replica_client.go:194–228  ·  view source on GitHub ↗

OpenLTXFile returns a reader for an LTX file. Returns os.ErrNotExist if no matching file is found.

(ctx context.Context, level int, minTXID, maxTXID ltx.TXID, offset, size int64)

Source from the content-addressed store, hash-verified

192// OpenLTXFile returns a reader for an LTX file.
193// Returns os.ErrNotExist if no matching file is found.
194func (c *ReplicaClient) OpenLTXFile(ctx context.Context, level int, minTXID, maxTXID ltx.TXID, offset, size int64) (io.ReadCloser, error) {
195 if err := c.Init(ctx); err != nil {
196 return nil, err
197 }
198
199 // Build the key from the file info
200 filename := ltx.FormatFilename(minTXID, maxTXID)
201 key := c.ltxPath(level, filename)
202
203 request := &oss.GetObjectRequest{
204 Bucket: oss.Ptr(c.Bucket),
205 Key: oss.Ptr(key),
206 }
207
208 // Set range header if offset is specified
209 if size > 0 {
210 request.RangeBehavior = oss.Ptr("standard")
211 request.Range = oss.Ptr(fmt.Sprintf("bytes=%d-%d", offset, offset+size-1))
212 } else if offset > 0 {
213 request.RangeBehavior = oss.Ptr("standard")
214 request.Range = oss.Ptr(fmt.Sprintf("bytes=%d-", offset))
215 }
216
217 result, err := c.client.GetObject(ctx, request)
218 if err != nil {
219 if isNotExists(err) {
220 return nil, os.ErrNotExist
221 }
222 return nil, fmt.Errorf("oss: get object %s: %w", key, err)
223 }
224
225 internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "GET").Inc()
226
227 return result.Body, nil
228}
229
230// WriteLTXFile writes an LTX file to the replica.
231// Extracts timestamp from LTX header and stores it in OSS metadata to preserve original creation time.

Callers

nothing calls this directly

Implementers 12

followTestReplicaClientreplica_internal_test.go
delayedReplicaClientstore_compaction_remote_test.go
testReplicaClientdb_internal_test.go
ReplicaClientwebdav/replica_client.go
ReplicaClientoss/replica_client.go
ReplicaClients3/replica_client.go
ReplicaClientfile/replica_client.go
ReplicaClientgs/replica_client.go
ReplicaClientmock/replica_client.go
ReplicaClientabs/replica_client.go
ReplicaClientnats/replica_client.go
ReplicaClientsftp/replica_client.go

Calls 4

InitMethod · 0.95
ltxPathMethod · 0.95
GetObjectMethod · 0.80
isNotExistsFunction · 0.70

Tested by

no test coverage detected