-
Notifications
You must be signed in to change notification settings - Fork 5
/
garbage-mpu-cleaner.js
212 lines (190 loc) · 7.43 KB
/
garbage-mpu-cleaner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*
* Copyright 2020 Joyent, Inc.
*/
//
// This program exists to consume items from the:
//
// manta_uploads
//
// Moray bucket(s) for a directory-based Manta installation, and for each
// completed upload record found, it will attempt to delete the associated
// intermediate MPU parts and directory from the "manta" Moray bucket.
//
//
// Config Options: (TODO explain what each of these does and how set)
//
// * admin_ip
// * datacenter
// * dir_shards (array of objects with a 'host' (DNS hostname) property)
// * instance
// * emoray (emoray.options.cueballOptions.resolvers, emoray.options.srvDomain)
// * moray (moray.options.cueballOptions.resolvers)
// * mpu_cleanup_age_seconds
// * mpu_cleanup_batch_interval_ms
// * mpu_cleanup_batch_size
// * server_uuid
//
var createMetricsManager = require('triton-metrics').createMetricsManager;
var restify = require('restify');
var vasync = require('vasync');
var common = require('../lib/common');
var GarbageMpuCleaner = require('../lib/garbage-mpu-cleaner');
var GarbageMpuPartsCleaner = require('../lib/garbage-mpu-parts-cleaner');
var elapsedSince = common.elapsedSince;
var METRIC_PREFIX = 'gc_mpu_cleaner_';
var METRICS_SERVER_PORT = 8884;
var SERVICE_NAME = 'garbage-mpu-cleaner';
function main() {
var beginning;
var logger;
beginning = process.hrtime();
vasync.pipeline(
{
arg: {},
funcs: [
function _createLogger(_, cb) {
logger = common.createLogger({
level: 'info',
name: SERVICE_NAME
});
cb();
},
function _loadConfig(ctx, cb) {
common.loadConfig({log: logger}, function _onConfig(
err,
cfg
) {
if (!err) {
ctx.config = cfg;
}
cb(err);
});
},
function _validateConfig(ctx, cb) {
common.validateConfig(ctx.config, function _onValidated(
err
) {
cb(err);
});
},
function _setupMetrics(ctx, cb) {
var metricsManager = createMetricsManager({
address: ctx.config.admin_ip,
log: logger,
staticLabels: {
datacenter: ctx.config.datacenter,
instance: ctx.config.instance,
server: ctx.config.server_uuid,
service: SERVICE_NAME
},
port: METRICS_SERVER_PORT,
restify: restify
});
metricsManager.createNodejsMetrics();
metricsManager.listen(cb);
ctx.metricsManager = metricsManager;
},
function _createMpuPartsCleaner(ctx, cb) {
//
// We want just *one* connection to electric-moray, so we
// create that here. The GarbageMpuCleaners call the
// metadataDeleter function from this and that will add them
// to the queue to be processed. When processing for the
// batch is complete, the callback will be called so the
// GarbageMpuCleaner instance knows it can remove those
// manta_upload records which succeeded. (we'll pass them
// back by _id).
//
var childLog;
childLog = logger.child(
{component: 'GarbageMpuPartsCleaner'},
true
);
ctx.mpc = new GarbageMpuPartsCleaner({
config: ctx.config,
log: childLog,
metricPrefix: METRIC_PREFIX,
metricsManager: ctx.metricsManager,
emorayConfig: common.getEMorayConfig({
collector: ctx.metricsManager.collector,
config: ctx.config,
log: childLog
})
});
ctx.mpc.start(cb);
},
function _createMpuCleaners(ctx, cb) {
var childLog;
var idx;
var gmc;
var shard;
var shards = [];
if (ctx.config.dir_shards.length < 1) {
cb(new Error('No dir-style shards configured for GC.'));
return;
}
//
// We create a separate GarbageMpuCleaner instance for each
// Moray shard this GC is assigned to manage.
//
for (idx = 0; idx < ctx.config.dir_shards.length; idx++) {
shard = ctx.config.dir_shards[idx].host;
childLog = logger.child(
{
component: 'GarbageMpuCleaner',
shard: shard
},
true
);
gmc = new GarbageMpuCleaner({
config: ctx.config,
log: childLog,
metadataDeleter: ctx.mpc.metadataDeleter.bind(
ctx.mpc
),
metricPrefix: METRIC_PREFIX,
metricsManager: ctx.metricsManager,
morayConfig: common.getMorayConfig({
collector: ctx.metricsManager.collector,
config: ctx.config,
log: childLog,
morayShard: shard
}),
shard: shard
});
gmc.start();
shards.push(gmc);
}
ctx.metricsManager.collector
.gauge({
name: METRIC_PREFIX + 'moray_shard_count',
help:
'Number of Moray shards from which this ' +
'garbage-mpu-cleaner instance is cleaning.'
})
.set(shards.length);
cb();
}
]
},
function _doneMain(err) {
if (err) {
logger.error(
{elapsed: elapsedSince(beginning), err: err},
'Startup failed.'
);
return;
}
logger.info(
{elapsed: elapsedSince(beginning)},
'Startup complete.'
);
}
);
}
main();