Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/file-server/zfs/config.ts
1447 views
1
import { join } from "path";
2
import { databaseFilename } from "./names";
3
4
// we ONLY put filesystems on pools whose name have this prefix.
5
// all other pools are ignored. We also mount everything in /{PREFIX} on the filesystem.
6
const PREFIX = process.env.COCALC_TEST_MODE ? "cocalcfs-test" : "cocalcfs";
7
8
const DATA = `/${PREFIX}`;
9
10
const SQLITE3_DATABASE_FILE = databaseFilename(DATA);
11
12
// Directory on server where filesystems get mounted (so NFS can serve them)
13
const FILESYSTEMS = join(DATA, "filesystems");
14
15
// Directory on server where zfs send streams (and tar?) are stored
16
const ARCHIVES = join(DATA, "archives");
17
18
// Directory to store data used in pulling as part of sync.
19
// E.g., this keeps around copies of the sqlite state database of each remote.
20
const PULL = join(DATA, "pull");
21
22
// Directory for bup
23
const BUP = join(DATA, "bup");
24
25
export const context = {
26
namespace: process.env.NAMESPACE ?? "default",
27
PREFIX,
28
DATA,
29
SQLITE3_DATABASE_FILE,
30
FILESYSTEMS,
31
ARCHIVES,
32
PULL,
33
BUP,
34
};
35
36
// WARNING: this "setContext" is global. It's very useful for **UNIT TESTING**, but
37
// for any other use, you want to set this at most once and never again!!! The reason
38
// is because with nodejs you could have async code running all over the place, and
39
// changing the context out from under it would lead to nonsense and corruption.
40
export function setContext({
41
namespace,
42
prefix,
43
}: {
44
namespace?: string;
45
prefix?: string;
46
}) {
47
context.namespace = namespace ?? process.env.NAMESPACE ?? "default";
48
context.PREFIX = prefix ?? PREFIX;
49
context.DATA = `/${context.PREFIX}`;
50
context.SQLITE3_DATABASE_FILE = databaseFilename(context.DATA);
51
context.FILESYSTEMS = join(context.DATA, "filesystems");
52
context.ARCHIVES = join(context.DATA, "archives");
53
context.PULL = join(context.DATA, "pull");
54
context.BUP = join(context.DATA, "bup");
55
}
56
57
// Every filesystem has at least this much quota (?)
58
export const MIN_QUOTA = 1024 * 1024 * 1; // 1MB
59
60
// We periodically do "zpool list" to find out what pools are available
61
// and how much space they have left. This info is cached for this long
62
// to avoid excessive calls:
63
export const POOLS_CACHE_MS = 15000;
64
65
// two hour default for running any commands (e.g., zfs send/recv)
66
export const DEFAULT_EXEC_TIMEOUT_MS = 2 * 1000 * 60 * 60;
67
68
// **all** user files for filesystems have this owner and group.
69
export const UID = 2001;
70
export const GID = 2001;
71
72
// We make/update snapshots periodically, with this being the minimum interval.
73
export const SNAPSHOT_INTERVAL_MS = 60 * 30 * 1000;
74
//export const SNAPSHOT_INTERVAL_MS = 10 * 1000;
75
76
// Lengths of time in minutes to keep these snapshots
77
export const SNAPSHOT_INTERVALS_MS = {
78
halfhourly: 30 * 1000 * 60,
79
daily: 60 * 24 * 1000 * 60,
80
weekly: 60 * 24 * 7 * 1000 * 60,
81
monthly: 60 * 24 * 7 * 4 * 1000 * 60,
82
};
83
84
// How many of each type of snapshot to retain
85
export const SNAPSHOT_COUNTS = {
86
halfhourly: 24,
87
daily: 14,
88
weekly: 7,
89
monthly: 4,
90
};
91
92
// Minimal interval for bup backups
93
export const BUP_INTERVAL_MS = 24 * 1000 * 60 * 60;
94
95
// minimal interval for zfs streams
96
export const STREAM_INTERVAL_MS = 24 * 1000 * 60 * 60;
97
// when more than this many streams, we recompact down
98
export const MAX_STREAMS = 30;
99
100