Skip to content

Commit d251916

Browse files
authored
Merge pull request #8256 from jackyalbo/jacky-pers_log
Adding node support for bucket logging
2 parents 2e73bae + 2b2f87a commit d251916

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/endpoint/endpoint.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ async function main(options = {}) {
130130
dbg.log0('Configured Virtual Hosts:', virtual_hosts);
131131
dbg.log0('Configured Location Info:', location_info);
132132

133+
const node_name = process.env.NODE_NAME || os.hostname();
133134
bucket_logger = config.BUCKET_LOG_TYPE === 'PERSISTENT' &&
134-
new PersistentLogger(config.PERSISTENT_BUCKET_LOG_DIR, config.PERSISTENT_BUCKET_LOG_NS, {
135+
new PersistentLogger(config.PERSISTENT_BUCKET_LOG_DIR, config.PERSISTENT_BUCKET_LOG_NS + '_' + node_name, {
135136
locking: 'SHARED',
136137
poll_interval: config.NSFS_GLACIER_LOGS_POLL_INTERVAL,
137138
});

src/util/bucket_logs_utils.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ const dbg = require('../util/debug_module')(__filename);
55
const config = require('../../config');
66
const stream = require('stream');
77
const crypto = require('crypto');
8+
const path = require('path');
89
const { PersistentLogger, LogFile } = require('../util/persistent_logger');
910
const { format_aws_date } = require('../util/time_utils');
1011
const nsfs_schema_utils = require('../manage_nsfs/nsfs_schema_utils');
1112
const Semaphore = require('../util/semaphore');
1213
const P = require('../util/promise');
14+
const nb_native = require('../util/nb_native');
1315

1416
const sem = new Semaphore(config.BUCKET_LOG_CONCURRENCY);
1517

@@ -27,16 +29,21 @@ const BUCKET_NAME_DEL = "_";
2729
* @param {AWS.S3} s3_connection
2830
* @param {function} bucket_to_owner_keys_func
2931
*/
30-
async function export_logs_to_target(config_fs, s3_connection, bucket_to_owner_keys_func) {
31-
const log = new PersistentLogger(config.PERSISTENT_BUCKET_LOG_DIR, config.PERSISTENT_BUCKET_LOG_NS, { locking: 'EXCLUSIVE' });
32-
try {
33-
return log.process(async file => _upload_to_targets(config_fs, s3_connection, file, bucket_to_owner_keys_func));
34-
} catch (err) {
35-
dbg.error('processing log file failed', log.file);
36-
throw err;
37-
} finally {
38-
await log.close();
39-
}
32+
async function export_logs_to_target(fs_context, s3_connection, bucket_to_owner_keys_func) {
33+
const entries = await nb_native().fs.readdir(fs_context, config.PERSISTENT_BUCKET_LOG_DIR);
34+
const results = await P.map_with_concurrency(5, entries, async entry => {
35+
if (!entry.name.endsWith('.log')) return;
36+
const log = new PersistentLogger(config.PERSISTENT_BUCKET_LOG_DIR, path.parse(entry.name).name, { locking: 'EXCLUSIVE' });
37+
try {
38+
return log.process(async file => _upload_to_targets(fs_context, s3_connection, file, bucket_to_owner_keys_func));
39+
} catch (err) {
40+
dbg.error('processing log file failed', log.file);
41+
throw err;
42+
} finally {
43+
await log.close();
44+
}
45+
});
46+
return !results.includes(false);
4047
}
4148

4249
/**

0 commit comments

Comments
 (0)