feat(sync): добавил механизм синхронизации хранилищ и управление группами
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package com.github.nullptroma.wallenc.domain.datatypes
|
||||
|
||||
import java.time.Instant
|
||||
import java.util.UUID
|
||||
|
||||
enum class StorageSyncOperation {
|
||||
UPSERT,
|
||||
DELETE,
|
||||
}
|
||||
|
||||
data class StorageSyncRevision(
|
||||
val sequence: Long,
|
||||
val actorId: String,
|
||||
val createdAt: Instant,
|
||||
)
|
||||
|
||||
data class StorageSyncJournalEntry(
|
||||
val path: String,
|
||||
val operation: StorageSyncOperation,
|
||||
val revision: StorageSyncRevision,
|
||||
val size: Long? = null,
|
||||
val originStorageUuid: UUID? = null,
|
||||
)
|
||||
|
||||
data class StorageSyncLock(
|
||||
val holderId: String,
|
||||
val leaseUntil: Instant,
|
||||
val updatedAt: Instant,
|
||||
)
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.github.nullptroma.wallenc.domain.interfaces
|
||||
|
||||
import com.github.nullptroma.wallenc.domain.datatypes.DataPage
|
||||
import com.github.nullptroma.wallenc.domain.datatypes.StorageSyncJournalEntry
|
||||
import com.github.nullptroma.wallenc.domain.datatypes.StorageSyncLock
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import java.time.Instant
|
||||
|
||||
interface IStorageAccessor {
|
||||
val size: StateFlow<Long?>
|
||||
@@ -48,4 +51,12 @@ interface IStorageAccessor {
|
||||
*/
|
||||
suspend fun openReadSystemFile(name: String): InputStream
|
||||
suspend fun openWriteSystemFile(name: String): OutputStream
|
||||
|
||||
suspend fun readSyncJournal(): List<StorageSyncJournalEntry>
|
||||
suspend fun appendSyncJournal(entries: List<StorageSyncJournalEntry>)
|
||||
suspend fun rewriteSyncJournal(entries: List<StorageSyncJournalEntry>)
|
||||
|
||||
suspend fun readSyncLock(): StorageSyncLock?
|
||||
suspend fun tryAcquireSyncLock(holderId: String, leaseUntil: Instant): Boolean
|
||||
suspend fun releaseSyncLock(holderId: String)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.github.nullptroma.wallenc.domain.interfaces
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
data class StorageSyncGroup(
|
||||
val id: String,
|
||||
val storageUuids: Set<UUID>,
|
||||
)
|
||||
|
||||
interface IStorageSyncGroupStore {
|
||||
suspend fun getGroups(): List<StorageSyncGroup>
|
||||
suspend fun putGroup(group: StorageSyncGroup)
|
||||
suspend fun removeGroup(groupId: String)
|
||||
}
|
||||
|
||||
interface IStorageSyncEngine {
|
||||
suspend fun syncAllGroups(
|
||||
reportProgress: (suspend (fraction: Float?, label: String?) -> Unit)? = null,
|
||||
)
|
||||
suspend fun syncGroup(
|
||||
groupId: String,
|
||||
reportProgress: (suspend (fraction: Float?, label: String?) -> Unit)? = null,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user