-
Notifications
You must be signed in to change notification settings - Fork 5
/
garbage-buckets-consumer.js
221 lines (202 loc) · 7.49 KB
/
garbage-buckets-consumer.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
213
214
215
216
217
218
219
220
221
/*
* 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 buckets-mdapi's garbage tables using the
// interfaces added with MANTA-4320.
//
// This means calling the `getgcbatch` RPC and writing instructions out to
// local "instructions" files in:
//
// * /var/spool/manta_gc/<storageId>/*
//
// where they will be picked up and transferred to the storage zones for
// processing. Once records are written out locally, they will be removed from
// buckets-mdapi using the `deletegcbatch` RPC.
//
// The Instructions files have:
//
// * storageId
// * "DELETEv2"
// * object path
// * shardId
// * bytes (for metrics/auditing)
//
// and therefore contain everything that's necessary to actually collect garbage
// on the individual storage/mako zones ("sharks").
//
//
// Config Options: (TODO explain what each of these does and how set)
//
// * admin_ip
// * buckets_mdapi (buckets_mdapi.options.cueballOptions.resolvers)
// * buckets_shards (array of objects with a 'host' (DNS hostname) property)
// * datacenter
// * instance
// * buckets_batch_interval_ms
// * server_uuid
//
var createMetricsManager = require('triton-metrics').createMetricsManager;
var restify = require('restify');
var vasync = require('vasync');
var common = require('../lib/common');
var GarbageBucketsConsumer = require('../lib/garbage-buckets-consumer');
var elapsedSince = common.elapsedSince;
var ensureDelegated = common.ensureDelegated;
var METRIC_PREFIX = 'gc_buckets_consumer_';
var METRICS_SERVER_PORT = 8881;
var SERVICE_NAME = 'garbage-buckets-consumer';
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 _ensureDelegated(_, cb) {
//
// If we don't have a delegated dataset, we're not going to do
// anything else since it would be dangerous to write any files
// locally.
//
ensureDelegated(function _delegatedResult(err, found) {
logger.debug(
{
err: err,
found: found
},
'ensureDelegated result.'
);
if (err) {
cb(err);
} else if (!found) {
cb(
new Error(
'Instruction root not on delegated ' +
'dataset, unsafe to continue.'
)
);
} else {
cb();
}
});
},
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 _createBucketsConsumer(ctx, cb) {
var childLog;
var idx;
var gdc;
var shard;
var shards = [];
if (ctx.config.buckets_shards.length < 1) {
cb(new Error('No buckets shards configured for GC.'));
return;
}
//
// We create a separate GarbageBucketsConsumer instance for each
// buckets-mdapi shard this GC is assigned to manage.
//
for (
idx = 0;
idx < ctx.config.buckets_shards.length;
idx++
) {
shard = ctx.config.buckets_shards[idx].host;
childLog = logger.child(
{
component: 'GarbageBucketsConsumer',
shard: shard
},
true
);
gdc = new GarbageBucketsConsumer({
config: ctx.config,
log: childLog,
metricPrefix: METRIC_PREFIX,
metricsManager: ctx.metricsManager,
bucketsMdapiConfig: common.getBucketsMdapiConfig({
collector: ctx.metricsManager.collector,
config: ctx.config,
log: childLog,
bucketsMdapiShard: shard
}),
shard: shard
});
gdc.start();
shards.push(gdc);
}
ctx.metricsManager.collector
.gauge({
name: METRIC_PREFIX + 'mdapi_shard_count',
help:
'Number of buckets-mdapi shards from which this ' +
'garbage-buckets-consumer instance is consuming.'
})
.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();