Skip to content

Commit

Permalink
Passing list of collection info to Storage maintain method
Browse files Browse the repository at this point in the history
Passing list of collection info to Storage maintain method
  • Loading branch information
hirenkp2000 authored Aug 3, 2023
2 parents 3fe64d2 + 6a820c6 commit 4ab2bf0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.here.naksha.lib.core.lambdas.Pe1;
import com.here.naksha.lib.core.models.TxSignalSet;
import java.util.List;
import org.jetbrains.annotations.NotNull;

/**
Expand All @@ -32,16 +33,14 @@ public interface IStorage {
/**
* Perform storage initialization, especially useful when invoked for the first time storage is to be accessed.
*/
default void init() {
maintain();
}
void init();

/**
* Perform maintenance tasks, for example garbage collect features that are older than the set {@link CollectionInfo#getMaxAge()}. This
* task is at least called ones every 12 hours. It is guaranteed that this is only executed on one Naksha instances at a given time, so
* there is no concurrent execution.
*/
void maintain();
void maintain(@NotNull List<CollectionInfo> collectionInfoList);

/**
* Create default transaction settings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@

import com.here.naksha.lib.core.lambdas.Pe1;
import com.here.naksha.lib.core.models.TxSignalSet;
import com.here.naksha.lib.core.storage.IMasterTransaction;
import com.here.naksha.lib.core.storage.IReadTransaction;
import com.here.naksha.lib.core.storage.IStorage;
import com.here.naksha.lib.core.storage.ITransactionSettings;
import com.here.naksha.lib.core.storage.*;
import com.here.naksha.lib.core.util.fib.FibSet;
import java.util.List;
import org.jetbrains.annotations.NotNull;

public class HeapCache implements IStorage {
Expand All @@ -39,9 +37,12 @@ public HeapCache(@NotNull HeapCacheConfig config) {
protected final @NotNull FibSet<String, CacheEntry> cache = new FibSet<>(CacheEntry::new);

@Override
public void maintain() {
public void init() {}

@Override
public void maintain(@NotNull List<CollectionInfo> collectionInfoList) {
if (config.storage != null) {
config.storage.maintain();
config.storage.maintain(collectionInfoList);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.here.naksha.lib.core.models.TxSignalSet;
import com.here.naksha.lib.core.models.features.Connector;
import com.here.naksha.lib.core.models.features.Storage;
import com.here.naksha.lib.core.storage.CollectionInfo;
import com.here.naksha.lib.core.storage.IStorage;
import com.here.naksha.lib.core.storage.ITransactionSettings;
import com.here.naksha.lib.core.util.IoHelp;
Expand All @@ -37,6 +38,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.postgresql.util.PSQLException;

Expand Down Expand Up @@ -224,7 +226,7 @@ public void init() {
* @throws SQLException If any error occurred.
*/
@Override
public void maintain() {
public void maintain(@NotNull List<CollectionInfo> collectionInfoList) {
try (final Connection conn = dataSource.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
stmt.execute(new StringBuilder()
Expand Down

0 comments on commit 4ab2bf0

Please sign in to comment.