-
-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -38,16 +38,17 @@ import com.reposilite.storage.type | |||||||||||||||||||
import io.javalin.http.ContentType | ||||||||||||||||||||
import io.javalin.http.ContentType.APPLICATION_OCTET_STREAM | ||||||||||||||||||||
import io.javalin.http.HttpStatus.INSUFFICIENT_STORAGE | ||||||||||||||||||||
import java.io.Closeable | ||||||||||||||||||||
import java.io.File | ||||||||||||||||||||
import java.io.FilterInputStream | ||||||||||||||||||||
import java.io.IOException | ||||||||||||||||||||
import java.io.InputStream | ||||||||||||||||||||
import java.nio.file.FileAlreadyExistsException | ||||||||||||||||||||
import java.nio.file.Files | ||||||||||||||||||||
import java.nio.file.NoSuchFileException | ||||||||||||||||||||
import java.nio.file.Path | ||||||||||||||||||||
import java.nio.file.StandardCopyOption.REPLACE_EXISTING | ||||||||||||||||||||
import java.nio.file.StandardCopyOption | ||||||||||||||||||||
import java.nio.file.attribute.FileTime | ||||||||||||||||||||
import kotlin.io.path.absolutePathString | ||||||||||||||||||||
import java.util.concurrent.Executors | ||||||||||||||||||||
import java.util.concurrent.locks.ReentrantLock | ||||||||||||||||||||
import kotlin.streams.asSequence | ||||||||||||||||||||
import panda.std.Result | ||||||||||||||||||||
import panda.std.asSuccess | ||||||||||||||||||||
|
@@ -60,7 +61,40 @@ abstract class FileSystemStorageProvider protected constructor( | |||||||||||||||||||
val rootDirectory: Path | ||||||||||||||||||||
) : StorageProvider { | ||||||||||||||||||||
|
||||||||||||||||||||
override fun shutdown() {} | ||||||||||||||||||||
data class LockedLocation( | ||||||||||||||||||||
val location: Location, | ||||||||||||||||||||
val lock: ReentrantLock = ReentrantLock(), | ||||||||||||||||||||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dzikoysk
Author
Owner
|
.map { inputStream -> | |
object : FilterInputStream(inputStream) { | |
override fun close() { | |
lock.use { | |
inputStream.close() | |
} | |
} | |
} | |
} |
Locking using regular locks is limited to the same thread, otherwise you'll raise an illegal monitor state exception trying to unlock this from some other thread (that called close()
). The performance of the locking mechanism itself is not important here.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
ivy-cst
Feb 5, 2024
Here I would use a 'java.util.concurrent.ConcurrentHashMap' and use the computeIfAbsent method to generate the LockedLocation for a locaton.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
dzikoysk
Feb 5, 2024
•
edited
Loading
Author
Owner
edited
As long as we're syncing this via the same thread, there's no need for a concurrent hashmap impl, because it's always called from the same thread. Also, having only computeIfAbsent
without the update usage counter (handled by compute
) method, we wouldn't be able to make thread-safe cleanups. I guess you made that assumption having in mind the ReentrantReadWriteLock
where we can obtain read/write count, as far as I remember - if so, that's a fair point to reconsider this lock.
I would recommend to use a
java.util.concurrent.locks.ReentrantReadWriteLock
per location.Then lockManager is not nescessary in my eyes.