Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions extensions/puterfs/PuterFSProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { v4 as uuidv4 } from 'uuid';
const { db } = extension.import('data');

const svc_metering = extension.import('service:meteringService');
const svc_trace = extension.import('service:traceService');
const svc_fs = extension.import('service:filesystem');
const { stuck_detector_stream, hashing_stream } = extension.import('core').util.streamutil;

Expand Down Expand Up @@ -63,6 +62,7 @@ const {

const {
ParallelTasks,
getTracer,
} = extension.import('core').util.otelutil;

const {
Expand Down Expand Up @@ -389,7 +389,7 @@ export default class PuterFSProvider {
// explicitly requested.

if ( options.tracer == null ) {
options.tracer = svc_trace.tracer;
options.tracer = getTracer();
}

if ( options.op ) {
Expand Down Expand Up @@ -468,7 +468,7 @@ export default class PuterFSProvider {
const actor = (context ?? Context).get('actor');
const user = actor.type.user;

const tracer = svc_trace.tracer;
const tracer = getTracer();
const uuid = uuidv4();
const timestamp = Math.round(Date.now() / 1000);
await parent.fetchEntry();
Expand Down Expand Up @@ -1016,7 +1016,7 @@ export default class PuterFSProvider {

svc_metering.incrementUsage(ownerActor, 'filesystem:delete:bytes', fileSize);

const tracer = svc_trace.tracer;
const tracer = getTracer();
const tasks = new ParallelTasks({ tracer, max: 4 });

tasks.add('remove-fsentry', async () => {
Expand Down
44 changes: 13 additions & 31 deletions extensions/puterfs/fsentries/FSEntryController.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ import Update from './Update.js';

const { db } = extension.import('data');
const svc_params = extension.import('service:params');
const svc_info = extension.import('service:information');

const { PuterPath } = extension.import('fs');

const { Context } = extension.import('core');

const { id2path } = extension.import('core').util.helpers;

const {
RootNodeSelector,
NodeChildSelector,
Expand All @@ -21,14 +16,14 @@ const {
NodeInternalIDSelector,
} = extension.import('core').fs.selectors;

export default class {
export default class FSEntryController {
static CONCERN = 'filesystem';

static STATUS_READY = {};
static STATUS_RUNNING_JOB = {};

constructor () {
this.status = this.constructor.STATUS_READY;
this.status = FSEntryController.STATUS_READY;

this.currentState = {
queue: [],
Expand Down Expand Up @@ -84,19 +79,6 @@ export default class {
},
], this);

// Register information providers

// uuid -> path via mysql
svc_info.given('fs.fsentry:uuid').provide('fs.fsentry:path')
.addStrategy('mysql', async uuid => {
// TODO: move id2path here
try {
return await id2path(uuid);
} catch (e) {
console.error('DASH VOID ERROR !!', e);
return `/-void/${ uuid}`;
}
});
}

mkPromiseForQueueSize_ () {
Expand Down Expand Up @@ -160,16 +142,16 @@ export default class {
}

const entry_already_enqueued =
this.currentState.updating_uuids.hasOwnProperty(selector.value) ||
this.deferredState.updating_uuids.hasOwnProperty(selector.value) ;
Object.prototype.hasOwnProperty.call(this.currentState.updating_uuids, selector.value) ||
Object.prototype.hasOwnProperty.call(this.deferredState.updating_uuids, selector.value) ;

if ( entry_already_enqueued ) {
callback();
return;
}

const k = `uid:${selector.value}`;
if ( ! this.entryListeners_.hasOwnProperty(k) ) {
if ( ! Object.prototype.hasOwnProperty.call(this.entryListeners_, k) ) {
this.entryListeners_[k] = [];
}

Expand Down Expand Up @@ -471,10 +453,10 @@ export default class {
throw new Error('Invalid operation');
}

const state = this.status === this.constructor.STATUS_READY ?
const state = this.status === FSEntryController.STATUS_READY ?
this.currentState : this.deferredState;

if ( ! state.updating_uuids.hasOwnProperty(op.uuid) ) {
if ( ! Object.prototype.hasOwnProperty.call(state.updating_uuids, op.uuid) ) {
state.updating_uuids[op.uuid] = [];
}
state.updating_uuids[op.uuid].push(state.queue.length);
Expand All @@ -483,7 +465,7 @@ export default class {

// DRY: same pattern as FSOperationContext:provideValue
// DRY: same pattern as FSOperationContext:rejectValue
if ( this.entryListeners_.hasOwnProperty(op.uuid) ) {
if ( Object.prototype.hasOwnProperty.call(this.entryListeners_, op.uuid) ) {
const listeners = this.entryListeners_[op.uuid];

delete this.entryListeners_[op.uuid];
Expand All @@ -495,19 +477,19 @@ export default class {
}

checkShouldExec_ () {
if ( this.status !== this.constructor.STATUS_READY ) return;
if ( this.status !== FSEntryController.STATUS_READY ) return;
if ( this.currentState.queue.length === 0 ) return;
this.exec_();
}

async exec_ () {
if ( this.status !== this.constructor.STATUS_READY ) {
if ( this.status !== FSEntryController.STATUS_READY ) {
throw new Error('Duplicate exec_ call');
}

const queue = this.currentState.queue;

this.status = this.constructor.STATUS_RUNNING_JOB;
this.status = FSEntryController.STATUS_RUNNING_JOB;

// const conn = await db_primary.promise().getConnection();
// await conn.beginTransaction();
Expand Down Expand Up @@ -539,7 +521,7 @@ export default class {
}

this.flipState_();
this.status = this.constructor.STATUS_READY;
this.status = FSEntryController.STATUS_READY;

for ( const op of queue ) {
op.status = op.constructor.STATUS_DONE;
Expand All @@ -559,4 +541,4 @@ export default class {
queueSizeResolve();
}
// #endregion
}
}
6 changes: 0 additions & 6 deletions src/backend/src/CoreModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,6 @@ const install = async ({ context, services, app, useapi, modapi }) => {
const { EntriService } = require('./services/EntriService.js');
services.registerService('entri-service', EntriService);

const { InformationService } = require('./services/information/InformationService');
services.registerService('information', InformationService);

const { TraceService } = require('./services/TraceService.js');
services.registerService('traceService', TraceService);

const { FilesystemService } = require('./filesystem/FilesystemService');
services.registerService('filesystem', FilesystemService);

Expand Down
32 changes: 20 additions & 12 deletions src/backend/src/filesystem/FSNodeContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const config = require('../config');
const _path = require('path');
const { NodeInternalIDSelector, NodeChildSelector, NodeUIDSelector, RootNodeSelector, NodePathSelector } = require('./node/selectors');
const { Context } = require('../util/context');
const { getTracer, span } = require('../util/otelutil');
const { NodeRawEntrySelector } = require('./node/selectors');
const { DB_READ } = require('../services/database/consts');
const { UserActorType, AppUnderUserActorType, Actor } = require('../services/auth/Actor');
Expand Down Expand Up @@ -135,7 +136,7 @@ module.exports = class FSNodeContext {
for ( const method of fetch_methods ) {
const original_method = this[method];
this[method] = async (...args) => {
const tracer = this.services.get('traceService').tracer;
const tracer = getTracer();
let result;
const opts = { attributes: {
selector: selector.describe(),
Expand Down Expand Up @@ -276,11 +277,22 @@ module.exports = class FSNodeContext {

async fetchPath () {
if ( this.path ) return;
if ( this.entry?.path ) {
this.path = this.entry.path;
return;
}
const uid = this.entry?.uuid ?? this.uid;
if ( ! uid ) return;
this.path = await this.#resolvePathFromUuid(uid);
}

this.path = await this.services.get('information')
.with('fs.fsentry')
.obtain('fs.fsentry:path')
.exec(this.entry);
async #resolvePathFromUuid (uuid) {
if ( ! uuid ) return undefined;
try {
return await id2path(uuid);
} catch (e) {
return `/-void/${ uuid }`;
}
}

/**
Expand All @@ -295,7 +307,7 @@ module.exports = class FSNodeContext {
*/
async fetchEntry (fetch_entry_options = {}) {
if ( this.fetching !== null ) {
await Context.get('services').get('traceService').spanify('fetching', async () => {
await span('fetching', async () => {
// ???: does this need to be double-checked? I'm not actually sure...
if ( this.fetching === null ) return;
await this.fetching;
Expand Down Expand Up @@ -839,8 +851,6 @@ module.exports = class FSNodeContext {
if ( fsentry.owner ) delete fsentry.owner.email;
}

const info = this.services.get('information');

if ( !this.uid && !this.entry.uuid ) {
console.warn(`Potential Error in getSafeEntry with no uid or entry.uuid ${
this.selector.describe() } ${
Expand All @@ -849,10 +859,8 @@ module.exports = class FSNodeContext {

// If fsentry was found by a path but the entry doesn't
// have a path, use the path that was used to find it.
fsentry.path = res.path ?? this.path ?? await info
.with('fs.fsentry:uuid')
.obtain('fs.fsentry:path')
.exec(this.uid ?? this.entry.uuid);
const entry_uid = this.uid ?? this.entry.uuid;
fsentry.path = res.path ?? this.path ?? await this.#resolvePathFromUuid(entry_uid);

if ( fsentry.path && fsentry.path.startsWith('/-void/') ) {
fsentry.broken = true;
Expand Down
9 changes: 0 additions & 9 deletions src/backend/src/filesystem/FilesystemService.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ class FilesystemService extends BaseService {
// used by update_child_paths
this.db = services.get('database').get(DB_WRITE, 'filesystem');

const info = services.get('information');
info.given('fs.fsentry').provide('fs.fsentry:path')
.addStrategy('entry-or-delegate', async entry => {
if ( entry.path ) return entry.path;
return await info
.with('fs.fsentry:uuid')
.obtain('fs.fsentry:path')
.exec(entry.uuid);
});
}

async _init () {
Expand Down
3 changes: 2 additions & 1 deletion src/backend/src/filesystem/hl_operations/hl_copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const { HLFilesystemOperation } = require('./definitions');
const { MkTree } = require('./hl_mkdir');
const { HLRemove } = require('./hl_remove');
const { LLCopy } = require('../ll_operations/ll_copy');
const { getTracer } = require('../../util/otelutil');

class HLCopy extends HLFilesystemOperation {
static DESCRIPTION = `
Expand Down Expand Up @@ -129,7 +130,7 @@ class HLCopy extends HLFilesystemOperation {
}

// NEXT: implement _verify_room with profiling
const tracer = svc.get('traceService').tracer;
const tracer = getTracer();
await tracer.startActiveSpan('fs:cp:verify-size-constraints', async span => {
const source_file = source.entry;
const dest_fsentry = parent.entry;
Expand Down
1 change: 0 additions & 1 deletion src/backend/src/filesystem/ll_operations/ll_copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class LLCopy extends LLFilesystemOperation {
const { source, parent, user, actor, target_name } = this.values;
const svc = context.get('services');

const tracer = svc.get('traceService').tracer;
const fs = svc.get('filesystem');
const svc_event = svc.get('event');

Expand Down
4 changes: 2 additions & 2 deletions src/backend/src/filesystem/ll_operations/ll_rmdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
const APIError = require('../../api/APIError');
const { MemoryFSProvider } = require('../../modules/puterfs/customfs/MemoryFSProvider');
const { ParallelTasks } = require('../../util/otelutil');
const { ParallelTasks, getTracer } = require('../../util/otelutil');
const FSNodeContext = require('../FSNodeContext');
const { NodeUIDSelector } = require('../node/selectors');
const { LLFilesystemOperation } = require('./definitions');
Expand Down Expand Up @@ -68,7 +68,7 @@ class LLRmDir extends LLFilesystemOperation {
throw APIError.create('not_empty');
}

const tracer = svc.get('traceService').tracer;
const tracer = getTracer();
const tasks = new ParallelTasks({ tracer, max: max_tasks });

for ( const child_uuid of children ) {
Expand Down
Loading
Loading