Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverse names for S3 sort #2

Merged
merged 2 commits into from
Feb 9, 2024
Merged
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
13 changes: 11 additions & 2 deletions src/s3vfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const LOCK_PAGE_OFFSET = 1073741824
export class S3VFS extends Base {
private readonly mapIdToPrefix = new Map<number, string>()
private readonly prefixToFlags = new Map<string, number>()
readonly maxFileNumber = 9999999999

constructor(
private readonly s3: S3,
Expand Down Expand Up @@ -126,7 +127,11 @@ export class S3VFS extends Base {
return this.handleAsync(async () => {
try {
const objects = await this.fetchObjects(fileId)
const size = (objects || []).reduce((size, { Size: blockSize }) => size + (blockSize || 0), 0)
// Capture the last non-slash characters
const filename = objects?.[0]?.Key?.match(/([^/]*)$/)?.[0];
const fileNumber = filename ? parseInt(filename) : this.maxFileNumber;
const fileCount = this.maxFileNumber - fileNumber
const size = fileCount ? (fileCount * this.blockSize) + this.blockSize : 0;
pSize64.set(size)
return SQLITE_OK
} catch (error) {
Expand Down Expand Up @@ -173,7 +178,11 @@ export class S3VFS extends Base {
}

private blockId(block: number) {
return ('0000000000'+block).slice(-10)
if(block > this.maxFileNumber) {
throw new Error(`File block number ${block} too great`)
}
const reverseBlock = this.maxFileNumber - block
return ('0000000000'+reverseBlock).slice(-10)
}

private blockObject(prefix: string, block: number) {
Expand Down