clean: remove unused caching mechanism

This commit is contained in:
KernelDeimos
2024-12-11 13:54:48 -05:00
parent df20cb8e6c
commit 4e0ce06982
5 changed files with 12 additions and 179 deletions
@@ -21,7 +21,6 @@ const { RESOURCE_STATUS_PENDING_CREATE } = require('../modules/puterfs/ResourceS
const DatabaseFSEntryFetcher = require("./storage/DatabaseFSEntryFetcher");
const { TraceService } = require('../services/TraceService.js');
const FSAccessContext = require('./FSAccessContext.js');
const SystemFSEntryService = require('./storage/SystemFSEntryService.js');
const PerformanceMonitor = require('../monitor/PerformanceMonitor.js');
const { NodePathSelector, NodeUIDSelector, NodeInternalIDSelector } = require('./node/selectors.js');
const FSNodeContext = require('./FSNodeContext.js');
@@ -56,8 +55,6 @@ class FilesystemService extends BaseService {
}));
// The new fs entry service
services.registerService('systemFSEntryService', SystemFSEntryService);
this.log = services.get('log-service').create('filesystem-service');
// used by update_child_paths
@@ -252,7 +249,7 @@ class FilesystemService extends BaseService {
await target.fetchEntry({ thumbnail: true });
const { _path, uuidv4 } = this.modules;
const systemFSEntryService = this.services.get('systemFSEntryService');
const svc_fsEntry = this.services.get('fsEntryService');
const ts = Math.round(Date.now() / 1000);
const uid = uuidv4();
@@ -282,7 +279,7 @@ class FilesystemService extends BaseService {
this.log.debug('creating fsentry', { fsentry: raw_fsentry })
const entryOp = await systemFSEntryService.insert(raw_fsentry);
const entryOp = await svc_fsEntry.insert(raw_fsentry);
console.log('entry op', entryOp);
@@ -319,7 +316,7 @@ class FilesystemService extends BaseService {
const { _path, uuidv4 } = this.modules;
const resourceService = this.services.get('resourceService');
const systemFSEntryService = this.services.get('systemFSEntryService');
const svc_fsEntry = this.services.get('fsEntryService');
const ts = Math.round(Date.now() / 1000);
const uid = uuidv4();
@@ -346,7 +343,7 @@ class FilesystemService extends BaseService {
this.log.debug('creating symlink', { fsentry: raw_fsentry })
const entryOp = await systemFSEntryService.insert(raw_fsentry);
const entryOp = await svc_fsEntry.insert(raw_fsentry);
(async () => {
await entryOp.awaitDone();
@@ -157,9 +157,9 @@ class LLCopy extends LLFilesystemOperation {
status: RESOURCE_STATUS_PENDING_CREATE,
});
const svc_fsentry = svc.get('systemFSEntryService');
const svc_fsEntry = svc.get('fsEntryService');
this.log.info(`inserting entry: ` + uuid);
const entryOp = await svc_fsentry.insert(raw_fsentry);
const entryOp = await svc_fsEntry.insert(raw_fsentry);
let node;
@@ -60,7 +60,7 @@ class LLMkdir extends LLFilesystemOperation {
const ts = Math.round(Date.now() / 1000);
const uid = uuidv4();
const resourceService = context.get('services').get('resourceService');
const systemFSEntryService = context.get('services').get('systemFSEntryService');
const svc_fsEntry = context.get('services').get('fsEntryService');
const svc_event = context.get('services').get('event');
const fs = context.get('services').get('filesystem');
@@ -109,7 +109,7 @@ class LLMkdir extends LLFilesystemOperation {
this.log.debug('creating fsentry', { fsentry: raw_fsentry })
this.checkpoint('about to enqueue insert');
const entryOp = await systemFSEntryService.insert(raw_fsentry);
const entryOp = await svc_fsEntry.insert(raw_fsentry);
this.field('fsentry-created', false);
@@ -136,7 +136,7 @@ class LLOWrite extends LLWriteBase {
const svc = Context.get('services');
const sizeService = svc.get('sizeService');
const resourceService = svc.get('resourceService');
const systemFSEntryService = svc.get('systemFSEntryService');
const svc_fsEntry = svc.get('fsEntryService');
const svc_event = svc.get('event');
// TODO: fs:decouple-versions
@@ -188,7 +188,7 @@ class LLOWrite extends LLWriteBase {
const filesize = file.size;
sizeService.change_usage(actor.type.user.id, filesize);
const entryOp = await systemFSEntryService.update(uid, raw_fsentry_delta);
const entryOp = await svc_fsEntry.update(uid, raw_fsentry_delta);
// depends on fsentry, does not depend on S3
(async () => {
@@ -235,7 +235,7 @@ class LLCWrite extends LLWriteBase {
const svc = Context.get('services');
const sizeService = svc.get('sizeService');
const resourceService = svc.get('resourceService');
const systemFSEntryService = svc.get('systemFSEntryService');
const svc_fsEntry = svc.get('fsEntryService');
const svc_event = svc.get('event');
const fs = svc.get('filesystem');
@@ -317,7 +317,7 @@ class LLCWrite extends LLWriteBase {
this.checkpoint('after change_usage');
const entryOp = await systemFSEntryService.insert(raw_fsentry);
const entryOp = await svc_fsEntry.insert(raw_fsentry);
this.checkpoint('after fsentry insert enqueue');
@@ -1,164 +0,0 @@
/*
* Copyright (C) 2024 Puter Technologies Inc.
*
* This file is part of Puter.
*
* Puter is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const { PuterPath } = require("../lib/PuterPath");
const _path = require('path');
// Redis keys:
// <env>:<service>:<class>:<type>:<property>:<id>
//
// note: <environment> is added by redisService automatically.
//
// If `<type>` is `multi`, then the format differs slightly:
// <env>:<service>:<class>:multi:<type>:<property>:<id-property>:<id>
// where `<id-property>` specifies the property being used for the id
class SystemFSEntryService {
constructor ({ services }) {
this.redis = { enabled: false };
this.DatabaseFSEntryService = services.get('fsEntryService');
this.log = services.get('log-service').create('system-fsentry-service');
// Register information providers
const info = services.get('information');
this.info = info;
if ( ! this.redis.enabled ) return;
// path -> uuid via redis
info.given('fs.fsentry:path').provide('fs.fsentry:uuid')
.addStrategy('redis', async path => {
return await this.get_uuid_from_path(path);
});
// uuid -> path via redis
info.given('fs.fsentry:uuid').provide('fs.fsentry:path')
.addStrategy('redis', async uuid => {
this.log.debug('getting path for: ' + uuid);
if ( uuid === PuterPath.NULL_UUID ) return '/';
const res = ( await this.redis.get(`fs:fsentry:path:path:${uuid}`) ) ?? undefined;
this.log.debug('got path: ' + res);
return res;
});
// uuid -> parent_uuid via redis
info.given('fs.fsentry:uuid').provide('fs.fsentry:children(fs.fsentry:uuid)')
.addStrategy('redis', async uuid => {
return await this.get_child_uuids(uuid);
});
}
async insert (entry) {
if ( this.redis.enabled ) {
await this._link(entry.uuid, entry.parent_uid, entry.name);
}
return await this.DatabaseFSEntryService.insert(entry);
}
async update (uuid, entry) {
// If parent_uid is set during an update, we assume that it
// has been changed. If it hasn't, no problem: just an extra
// cache invalidation; but the code that set it should know
// better because it probably has the fsentry data already.
if ( entry.hasOwnProperty('parent_uid') ) {
await this._relocate(uuid, entry.parent_uid)
}
return await this.DatabaseFSEntryService.update(uuid, entry);
}
async delete (uuid) {
//
}
async get_child_uuids (uuid) {
let members;
members = await this.redis.smembers(`fs:fsentry:set:childs:${uuid}`);
if ( members ) return members;
members = await this.DatabaseFSEntryService.get_descendants(uuid);
return members ?? [];
}
async get_uuid_from_path (path) {
path = PuterPath.adapt(path);
let pathOfReference = path.reference === PuterPath.NULL_UUID
? '/' : this.get_path_from_uuid(path.reference);
const fullPath = _path.join(pathOfReference, path.relativePortion);
let uuid = await this.redis.get(`fs:fsentry:multi:uuid:uuid:path:${fullPath}`);
return uuid;
}
// Cache related functions
async _link (subject_uuid, parent_uuid, subject_name) {
this.log.info(`linking ${subject_uuid} to ${parent_uuid}`);
// We need the parent's path to update everything
let pathOfParent = await this.info.with('fs.fsentry:uuid')
.obtain('fs.fsentry:path').exec(parent_uuid);
this.log.debug(`path of parent: ${pathOfParent}`);
if ( ! subject_name ) {
subject_name = await this.redis.get(`fs:fsentry:str:name:${subject_uuid}`);
}
// Register properties
await this.redis.set(`fs:fsentry:uuid:parent:${subject_uuid}`, parent_uuid);
await this.redis.set(`fs:fsentry:str:name:${subject_uuid}`, subject_name);
// Add as child of parent
await this.redis.sadd(`fs:fsentry:set:childs:${parent_uuid}`, subject_uuid);
// Register path
const subject_path = `${pathOfParent}/${subject_name}`;
this.log.debug(`registering path: ${subject_path} for ${subject_uuid}`);
await this.redis.set(`fs:fsentry:path:path:${subject_uuid}`, subject_path);
await this.redis.set(`fs:fsentry:multi:uuid:uuid:path:${subject_path}`, subject_uuid);
}
async _unlink (subject_uuid) {
let parent_uuid = await this.redis.get(`fs:fsentry:uuid:parent:${subject_uuid}`);
// TODO: try getting from database
// Remove from parent
await this.redis.srem(`fs:fsentry:set:childs:${parent_uuid}`, subject_uuid);
}
async _purge (subject_uuid) {
await this._unlink(subject_uuid);
// Remove properties
await this.redis.del(`fs:fsentry:uuid:parent:${subject_uuid}`);
await this.redis.del(`fs:fsentry:str:name:${subject_uuid}`);
// Remove path
const subject_path =
await this.redis.get(`fs:fsentry:path:path:${subject_uuid}`);
await this.redis.del(`fs:fsentry:path:path:${subject_uuid}`);
if ( subject_path ) {
await this.redis.del(`fs:fsentry:multi:uuid:path:${subject_path}`);
}
}
async _relocate (subject_uuid, new_parent_uuid) {
await this._unlink(subject_uuid);
await this._link(subject_uuid, new_parent_uuid);
}
}
module.exports = SystemFSEntryService;