Skip to content

Commit c0f5373

Browse files
committed
Added kdoc and disabled wildcard imports
1 parent e38c342 commit c0f5373

26 files changed

+283
-148
lines changed

.editorconfig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
11
root = true
2-
3-
[*.kt]
4-
ktlint_standard_no-wildcard-imports = disabled

src/integrationTest/java/org/radarbase/output/RestructureS3IntegrationTest.kt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
package org.radarbase.output
22

3-
import io.minio.*
3+
import io.minio.BucketExistsArgs
4+
import io.minio.GetObjectArgs
5+
import io.minio.ListObjectsArgs
6+
import io.minio.MakeBucketArgs
47
import io.minio.ObjectWriteArgs.MAX_PART_SIZE
5-
import kotlinx.coroutines.*
8+
import io.minio.PutObjectArgs
9+
import io.minio.RemoveBucketArgs
10+
import io.minio.RemoveObjectArgs
11+
import kotlinx.coroutines.Dispatchers
12+
import kotlinx.coroutines.coroutineScope
13+
import kotlinx.coroutines.joinAll
14+
import kotlinx.coroutines.launch
615
import kotlinx.coroutines.test.runTest
16+
import kotlinx.coroutines.withContext
717
import org.junit.jupiter.api.Assertions.assertEquals
818
import org.junit.jupiter.api.Test
9-
import org.radarbase.output.config.*
19+
import org.radarbase.output.config.PathConfig
20+
import org.radarbase.output.config.PathFormatterConfig
21+
import org.radarbase.output.config.ResourceConfig
22+
import org.radarbase.output.config.RestructureConfig
23+
import org.radarbase.output.config.S3Config
24+
import org.radarbase.output.config.TopicConfig
25+
import org.radarbase.output.config.WorkerConfig
1026
import org.radarbase.output.util.SuspendedCloseable.Companion.useSuspended
1127
import org.radarbase.output.util.Timer
1228
import org.radarbase.output.util.bucketBuild

src/integrationTest/java/org/radarbase/output/accounting/OffsetRangeRedisTest.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ package org.radarbase.output.accounting
22

33
import kotlinx.coroutines.test.runTest
44
import org.junit.jupiter.api.AfterEach
5-
import org.junit.jupiter.api.Assertions.*
5+
import org.junit.jupiter.api.Assertions.assertEquals
6+
import org.junit.jupiter.api.Assertions.assertFalse
7+
import org.junit.jupiter.api.Assertions.assertNotNull
8+
import org.junit.jupiter.api.Assertions.assertNull
9+
import org.junit.jupiter.api.Assertions.assertTrue
610
import org.junit.jupiter.api.BeforeEach
711
import org.junit.jupiter.api.Test
812
import org.radarbase.output.accounting.OffsetRedisPersistence.Companion.redisOffsetReader

src/main/java/org/radarbase/output/Application.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,26 @@ package org.radarbase.output
1818

1919
import com.beust.jcommander.JCommander
2020
import com.beust.jcommander.ParameterException
21-
import kotlinx.coroutines.*
21+
import kotlinx.coroutines.launch
22+
import kotlinx.coroutines.runBlocking
2223
import kotlinx.coroutines.sync.Mutex
2324
import kotlinx.coroutines.sync.Semaphore
24-
import org.radarbase.output.accounting.*
25+
import org.radarbase.output.accounting.Accountant
26+
import org.radarbase.output.accounting.OffsetPersistenceFactory
27+
import org.radarbase.output.accounting.OffsetRedisPersistence
28+
import org.radarbase.output.accounting.RedisHolder
29+
import org.radarbase.output.accounting.RedisRemoteLockManager
30+
import org.radarbase.output.accounting.RemoteLockManager
2531
import org.radarbase.output.cleaner.SourceDataCleaner
2632
import org.radarbase.output.compression.Compression
2733
import org.radarbase.output.config.CommandLineArgs
2834
import org.radarbase.output.config.RestructureConfig
2935
import org.radarbase.output.format.RecordConverterFactory
3036
import org.radarbase.output.path.RecordPathFactory
31-
import org.radarbase.output.source.*
37+
import org.radarbase.output.source.InMemoryStorageIndex
38+
import org.radarbase.output.source.SourceStorage
39+
import org.radarbase.output.source.SourceStorageFactory
40+
import org.radarbase.output.source.StorageIndexManager
3241
import org.radarbase.output.target.TargetStorage
3342
import org.radarbase.output.target.TargetStorageFactory
3443
import org.radarbase.output.util.Timer
@@ -92,12 +101,12 @@ class Application(
92101
}.map { Duration.ofSeconds(it) }
93102

94103
storageIndexManagers = config.paths.inputs.associateWith { input ->
95-
MutableStorageIndexManager(
104+
StorageIndexManager(
96105
InMemoryStorageIndex(),
97106
sourceStorage,
107+
input,
98108
fullScan,
99109
emptyScan,
100-
input,
101110
)
102111
}
103112
val serviceMutex = Mutex()

src/main/java/org/radarbase/output/format/JsonAvroConverterFactory.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import org.radarbase.output.format.JsonAvroConverter.Companion.JSON_READER
66
import org.radarbase.output.format.JsonAvroConverter.Companion.JSON_WRITER
77
import org.radarbase.output.util.ResourceContext.Companion.resourceContext
88
import org.radarbase.output.util.TimeUtil.getDate
9-
import java.io.*
9+
import java.io.BufferedReader
10+
import java.io.IOException
11+
import java.io.InputStream
12+
import java.io.Reader
13+
import java.io.Writer
1014
import java.nio.file.Path
1115
import kotlin.io.path.inputStream
1216

src/main/java/org/radarbase/output/format/RecordConverterFactory.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ import org.apache.avro.generic.GenericData
2121
import org.apache.avro.generic.GenericRecord
2222
import org.radarbase.output.compression.Compression
2323
import org.radarbase.output.util.ResourceContext.Companion.resourceContext
24-
import java.io.*
24+
import java.io.BufferedReader
25+
import java.io.IOException
26+
import java.io.InputStream
27+
import java.io.Reader
28+
import java.io.Writer
2529
import java.nio.file.Path
2630
import java.util.regex.Pattern
2731
import kotlin.collections.component1

src/main/java/org/radarbase/output/path/MPPathFormatterPlugin.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package org.radarbase.output.path
22

3-
import kotlinx.coroutines.*
3+
import kotlinx.coroutines.CoroutineScope
4+
import kotlinx.coroutines.Dispatchers
5+
import kotlinx.coroutines.SupervisorJob
6+
import kotlinx.coroutines.delay
7+
import kotlinx.coroutines.isActive
8+
import kotlinx.coroutines.launch
49
import org.radarbase.kotlin.coroutines.CacheConfig
510
import org.radarbase.kotlin.coroutines.CachedMap
611
import org.radarbase.ktor.auth.ClientCredentialsConfig

src/main/java/org/radarbase/output/source/DelegatingStorageIndex.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package org.radarbase.output.source
22

3+
/**
4+
* Delegate all calls directly to the underlying storage. This effectively means that no caching
5+
* takes place.
6+
*/
37
class DelegatingStorageIndex(
48
private val sourceStorage: SourceStorage,
59
) : StorageIndex {

src/main/java/org/radarbase/output/source/InMemoryStorageIndex.kt

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import java.nio.file.Path
55
import java.util.concurrent.ConcurrentHashMap
66
import java.util.concurrent.ConcurrentMap
77

8+
/**
9+
* Storage index that keeps the given file tree in memory.
10+
* For very large file systems, this may
11+
* cause a memory issue.
12+
*/
813
class InMemoryStorageIndex : MutableStorageIndex {
914
private val fileIndex: ConcurrentMap<StorageNode.StorageDirectory, Map<Path, StorageNode>> = ConcurrentHashMap()
1015
private val rootSet = ConcurrentHashMap<Path, StorageNode>()
@@ -27,35 +32,33 @@ class InMemoryStorageIndex : MutableStorageIndex {
2732
}
2833
}
2934

30-
private fun add(node: StorageNode) {
31-
var currentNode = node
32-
var parent = currentNode.parent()
33-
if (currentNode is StorageNode.StorageDirectory) {
34-
fileIndex.computeIfAbsent(currentNode) {
35-
mapOf()
36-
}
37-
}
38-
while (parent != null) {
39-
fileIndex.compute(parent) { _, map ->
35+
/** Adds a node and all its parents to the file hierarchy. */
36+
private fun add(dir: StorageNode.StorageDirectory) {
37+
var currentDir = dir
38+
var parentDir = currentDir.parent()
39+
while (parentDir != null) {
40+
fileIndex.compute(parentDir) { _, map ->
4041
if (map == null) {
41-
mapOf(currentNode.path to currentNode)
42+
mapOf(currentDir.path to currentDir)
4243
} else {
43-
val newMap = map.toMutableMap()
44-
newMap[currentNode.path] = currentNode
45-
newMap
44+
buildMap(map.size + 1) {
45+
putAll(map)
46+
put(currentDir.path, currentDir)
47+
}
4648
}
4749
}
48-
currentNode = parent
49-
parent = currentNode.parent()
50+
currentDir = parentDir
51+
parentDir = currentDir.parent()
5052
}
51-
rootSet[currentNode.path] = currentNode
53+
rootSet[currentDir.path] = currentDir
5254
}
5355

5456
override suspend fun addAll(parent: StorageNode.StorageDirectory, nodes: List<StorageNode>): Collection<StorageNode> {
5557
add(parent)
5658

5759
if (nodes.isEmpty()) {
58-
return fileIndex[parent]?.values ?: listOf()
60+
return fileIndex[parent]?.values
61+
?: listOf()
5962
}
6063

6164
nodes.asSequence()
@@ -81,7 +84,7 @@ class InMemoryStorageIndex : MutableStorageIndex {
8184
return newMap.values
8285
}
8386

84-
override suspend fun sync(parent: StorageNode.StorageDirectory, nodes: List<StorageNode>): Collection<StorageNode> {
87+
override suspend fun sync(parent: StorageNode.StorageDirectory, nodes: List<StorageNode>) {
8588
add(parent)
8689
val newMap = buildMap(nodes.size) {
8790
nodes.forEach { put(it.path, it) }
@@ -93,8 +96,6 @@ class InMemoryStorageIndex : MutableStorageIndex {
9396
.filterIsInstance<StorageNode.StorageDirectory>()
9497
.filter { it.path !in newMap }
9598
.forEach { removeRecursive(it) }
96-
97-
return newMap.values
9899
}
99100

100101
override suspend fun remove(file: StorageNode.StorageFile) {
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
package org.radarbase.output.source
22

3+
/** Storage index that may be modified by the storage index manager. */
34
interface MutableStorageIndex : StorageIndex {
5+
/**
6+
* Add a list of storage nodes to the given directory.
7+
* All values in [nodes] should have [parent] as parent node. No nodes will be removed from the
8+
* current directory listing, but updated values (e.g. last modified values) will be overridden.
9+
*
10+
* @return the current file listing after adding new nodes.
11+
*/
412
suspend fun addAll(parent: StorageNode.StorageDirectory, nodes: List<StorageNode>): Collection<StorageNode>
513

6-
suspend fun sync(parent: StorageNode.StorageDirectory, nodes: List<StorageNode>): Collection<StorageNode>
14+
/**
15+
* Fully sync a storage node list with the index.
16+
* All values in [nodes] should have [parent] as parent node. All nodes in the index
17+
* corresponding to [parent] will be removed from that directory and replaced by the given list.
18+
*/
19+
suspend fun sync(parent: StorageNode.StorageDirectory, nodes: List<StorageNode>)
720
}

0 commit comments

Comments
 (0)