holepunchto / drives

CLI to download, seed, and mirror a Hyperdrive or Localdrive
Apache License 2.0
24 stars 10 forks source link

Remove write lock from seed command #36

Open immetoo2 opened 4 months ago

immetoo2 commented 4 months ago

When seeding a hyper drive, it does a write lock while seeding is read only.

To reproduce, start seeding a drive;

drives seed <driveId>

And then every command fails with an write lock;

/home/jenkins/.nvm/versions/node/v22.1.0/lib/node_modules/drives/node_modules/random-access-file/index.js:249
  const err = new Error('ELOCKED: File is locked')
              ^

Error: ELOCKED: File is locked
    at createLockError (/home/jenkins/.nvm/versions/node/v22.1.0/lib/node_modules/drives/node_modules/random-access-file/index.js:249:15)
    at onopen (/home/jenkins/.nvm/versions/node/v22.1.0/lib/node_modules/drives/node_modules/random-access-file/index.js:105:19)
    at FSReqCallback.oncomplete (node:fs:188:23) {
  code: 'ELOCKED',
  path: '/home/jenkins/.drives/corestore/primary-key'
}

Node.js v22.1.0

Having to stop seeding to add a few files, feels really strange.

immetoo2 commented 4 months ago

The seed command block all commands including touching a new drive;

love.distributedrebirth.bassboon.warp.fault.FaultStreamDelegate: ELOCKED: File is locked
    at TraceSignal.JDat-Drives-Command=drives touch(JDatLocalFileSystem:0)
    at TraceSignal.JDat-Drives-Exit-Code=1(JDatLocalFileSystem:0)
    at TraceSignal.Fault-Section-Chain-Iceberg=love.distributedrebirth.bassboon.warp.fault.FaultStreamDelegateDuckTail(JDatLocalFileSystem:0)
    at TraceSignal.EcmaScript-Error-path=/home/willemtsade/.drives/corestore/primary-key(QuackJavaScriptDuckTales:0)
    at TraceSignal.Fault-Section-Chain-Message=ELOCKED: File is locked(QuackJavaScriptDuckTales:0)
    at TraceSignal.EcmaScript-Error-code=ELOCKED(QuackJavaScriptDuckTales:0)
    at love.distributedrebirth.bassboon.warp.fault.FaultStreamDelegate.valueOfDuckTail(FaultStreamDelegate.java:70)
    at love.distributedrebirth.bassboon.nx01.jdat.local.JDatLocalFileSystem.executeHyperdrive(JDatLocalFileSystem.java:376)
    at love.distributedrebirth.bassboon.nx01.jdat.local.JDatLocalFileSystem.cmdTouch(JDatLocalFileSystem.java:230)
    at love.distributedrebirth.bassboon.nx01.jdat.local.JDatLocalFileSystemTest.testUnicode(JDatLocalFileSystemTest.java:96)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Caused by: love.distributedrebirth.bassboon.warp.fault.FaultStreamDelegateDuckTail: ELOCKED: File is locked
    at this.createLockError(/home/willemtsade/.nvm/versions/node/v22.1.0/lib/node_modules/drives/node_modules/random-access-file/index.js:249)
    at this.onopen(/home/willemtsade/.nvm/versions/node/v22.1.0/lib/node_modules/drives/node_modules/random-access-file/index.js:105)
    at FSReqCallback.oncomplete(node:fs:188)

A workaround is having every drive in its own external managed storage path location, but that is counter productive.

davetapley commented 3 months ago

@immetoo2 new to drives / Holepunch, just testing out and ran in to this.

Can you elaborate on your workaround? I don't know what 'managed storage path' is, and nothing in docs 🤔

immetoo2 commented 3 months ago

The real code solution is the 'inverse of the problem' like;

@davetapley All command have an --storage <path> Storage path option, which can be used to keep all your drives in separate folders and thus locks, but this does not solve the seed problem.

To sync and seed a drive, a script like this may work;

while [ true ]
do
        sleep 2;
        echo "run cycle";
        drives mirror ...
        timeout 24h drives seed ...
done