Skip to content

Commit

Permalink
fixes - GCP not waiting for finish before resolve
Browse files Browse the repository at this point in the history
few fixes found during tests
issue with get_block_store_info schema - null instead of object
issue with new_tier having undefined for storage_class
adapting analyze_resource_gcp to use same code as block_store_google

Signed-off-by: jackyalbo <[email protected]>
  • Loading branch information
jackyalbo committed Mar 6, 2024
1 parent 29fc24a commit e15e773
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/agent/block_store_services/block_store_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const block_store_info_cache = new LRUCache({
max_usage: 1000,
expiry_ms: 2 * 60 * 1000,
make_key: params => params.options.address,
load: async ({ rpc_client, options }) => rpc_client.block_store.get_block_store_info(null, options),
load: async ({ rpc_client, options }) => rpc_client.block_store.get_block_store_info({}, options),
});
class BlockStoreClient {

Expand Down Expand Up @@ -98,8 +98,8 @@ class BlockStoreClient {
}
},
});
dbg.log3('writing block id to gcp: ', block_id);
await buffer_utils.write_to_stream(write_stream, data);
write_stream.end();
const data_length = data.length;
const usage = data_length ? {
size: (block_md.is_preallocated ? 0 : data_length) + encoded_md.length,
Expand Down
1 change: 0 additions & 1 deletion src/agent/block_store_services/block_store_google.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ class BlockStoreGoogle extends BlockStoreBase {
dbg.log3('writing block id to cloud: ', key);
try {
await buffer_utils.write_to_stream(write_stream, data);
write_stream.end();
const usage = {
size: data.length + encoded_md.length,
count: 1
Expand Down
4 changes: 2 additions & 2 deletions src/server/system_services/tier_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,13 @@ async function update_bucket_class(req) {
update_db = true;
}
check_tier_exists(req, new_name);
const new_tier = new_tier_defaults(
const new_tier = _.omitBy(new_tier_defaults(
new_name,
req.system._id,
chunk_config._id,
mirrors,
tier.storage_class
);
), _.isUndefined);
if (tier.data_placement) new_tier.data_placement = tier.data_placement;
if (old_tier) {
const old_tier_full = req.system.tiers_by_name[old_tier.unwrap()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const { inspect } = require('util');
const { Storage } = require('@google-cloud/storage');
const dbg = require('../../../util/debug_module')(__filename);
const buffer_utils = require('../../../util/buffer_utils');
dbg.set_process_name('analyze_resource');
const CloudVendor = require('./analyze_resource_cloud_vendor_abstract');

Expand Down Expand Up @@ -58,8 +59,7 @@ class AnalyzeGcp extends CloudVendor {
.bucket(bucket)
.file(key)
.createWriteStream();
stream.write(''); //write an empty file
stream.end();
await buffer_utils.write_to_stream(stream, ''); //write an empty file
stream.on('response', resp => {
dbg.log0(`Write of ${key} response: ${inspect(resp)}`);
});
Expand Down
3 changes: 2 additions & 1 deletion src/util/buffer_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,12 @@ function count_length(buffers) {
function write_to_stream(writable, buf) {
return new Promise((resolve, reject) => {
writable.once('error', reject);
writable.once('finish', resolve);
writable.write(buf, err => {
if (err) {
return reject(err);
}
return resolve();
writable.end();
});
});
}
Expand Down

0 comments on commit e15e773

Please sign in to comment.