Sort-of-working statcache implementation.
[cumulus.git] / localdb.h
1 /* LBS: An LFS-inspired filesystem backup system
2  * Copyright (C) 2007  Michael Vrable
3  *
4  * When creating backup snapshots, maintain a local database of data blocks and
5  * checksums, in addition to the data contents (which may be stored remotely).
6  * This database is consulted when attempting to build incremental snapshots,
7  * as it says which objects can be reused.
8  *
9  * The database is implemented as an SQLite3 database, but this implementation
10  * detail is kept internal to this file, so that the storage format may be
11  * changed later. */
12
13 #ifndef _LBS_LOCALDB_H
14 #define _LBS_LOCALDB_H
15
16 #include <sqlite3.h>
17
18 #include <string>
19
20 #include "ref.h"
21
22 class LocalDb {
23 public:
24     void Open(const char *path, const char *snapshot_name);
25     void Close();
26     void StoreObject(const ObjectReference& ref,
27                      const std::string &checksum, int64_t size, double age);
28     ObjectReference FindObject(const std::string &checksum, int64_t size);
29     bool IsOldObject(const std::string &checksum, int64_t size, double *age);
30     bool IsAvailable(const ObjectReference &ref);
31     void UseObject(const ObjectReference& ref);
32 private:
33     sqlite3 *db;
34     int64_t snapshotid;
35
36     sqlite3_stmt *Prepare(const char *sql);
37     int64_t SegmentToId(const std::string &segment);
38     std::string IdToSegment(int64_t segmentid);
39 };
40
41 #endif // _LBS_LOCALDB_H