Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
K
key_value-server
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
amir.yosef
key_value-server
Commits
1d9fb337
Commit
1d9fb337
authored
Aug 29, 2024
by
amir.yosef
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unstable Storage management
parent
5a79f2a4
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
137 additions
and
14 deletions
+137
-14
io_quarkus_caffeine.xml
.idea/libraries/io_quarkus_caffeine.xml
+80
-0
Redis.iml
Redis.iml
+1
-0
Cacheable.java
src/storage/Cacheable.java
+8
-0
CaffeineCachePolicy.java
src/storage/CaffeineCachePolicy.java
+44
-0
LRUCachePolicy.java
src/storage/LRUCachePolicy.java
+1
-1
Storage.java
src/storage/Storage.java
+3
-13
No files found.
.idea/libraries/io_quarkus_caffeine.xml
0 → 100644
View file @
1d9fb337
<component
name=
"libraryTable"
>
<library
name=
"io.quarkus.caffeine"
type=
"repository"
>
<properties
maven-id=
"io.quarkus:quarkus-caffeine:2.16.5.Final"
/>
<CLASSES>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/quarkus/quarkus-caffeine/2.16.5.Final/quarkus-caffeine-2.16.5.Final.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/quarkus/quarkus-core/2.16.5.Final/quarkus-core-2.16.5.Final.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/jakarta/annotation/jakarta.annotation-api/1.3.5/jakarta.annotation-api-1.3.5.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/jakarta/enterprise/jakarta.enterprise.cdi-api/2.0.2/jakarta.enterprise.cdi-api-2.0.2.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/jakarta/el/jakarta.el-api/3.0.3/jakarta.el-api-3.0.3.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/jakarta/interceptor/jakarta.interceptor-api/1.2.5/jakarta.interceptor-api-1.2.5.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/jakarta/ejb/jakarta.ejb-api/3.2.6/jakarta.ejb-api-3.2.6.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/jakarta/transaction/jakarta.transaction-api/1.3.2/jakarta.transaction-api-1.3.2.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/jakarta/inject/jakarta.inject-api/1.0/jakarta.inject-api-1.0.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/quarkus/quarkus-ide-launcher/2.16.5.Final/quarkus-ide-launcher-2.16.5.Final.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/quarkus/quarkus-development-mode-spi/2.16.5.Final/quarkus-development-mode-spi-2.16.5.Final.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/smallrye/config/smallrye-config/2.13.3/smallrye-config-2.13.3.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/smallrye/config/smallrye-config-core/2.13.3/smallrye-config-core-2.13.3.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/eclipse/microprofile/config/microprofile-config-api/2.0.1/microprofile-config-api-2.0.1.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/smallrye/common/smallrye-common-annotation/1.13.2/smallrye-common-annotation-1.13.2.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/smallrye/common/smallrye-common-expression/1.13.2/smallrye-common-expression-1.13.2.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/smallrye/common/smallrye-common-function/1.13.2/smallrye-common-function-1.13.2.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/smallrye/common/smallrye-common-constraint/1.13.2/smallrye-common-constraint-1.13.2.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/smallrye/common/smallrye-common-classloader/1.13.2/smallrye-common-classloader-1.13.2.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/ow2/asm/asm/9.4/asm-9.4.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/smallrye/config/smallrye-config-common/2.13.3/smallrye-config-common-2.13.3.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/jboss/logging/jboss-logging/3.5.0.Final/jboss-logging-3.5.0.Final.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/jboss/logmanager/jboss-logmanager-embedded/1.0.11/jboss-logmanager-embedded-1.0.11.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/jboss/logging/jboss-logging-annotations/2.2.1.Final/jboss-logging-annotations-2.2.1.Final.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/jboss/threads/jboss-threads/3.4.3.Final/jboss-threads-3.4.3.Final.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/jboss/slf4j/slf4j-jboss-logmanager/1.2.0.Final/slf4j-jboss-logmanager-1.2.0.Final.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/graalvm/sdk/graal-sdk/22.3.0/graal-sdk-22.3.0.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/wildfly/common/wildfly-common/1.5.4.Final-format-001/wildfly-common-1.5.4.Final-format-001.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/quarkus/quarkus-bootstrap-runner/2.16.5.Final/quarkus-bootstrap-runner-2.16.5.Final.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/smallrye/common/smallrye-common-io/1.13.2/smallrye-common-io-1.13.2.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/github/crac/org-crac/0.1.3/org-crac-0.1.3.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/quarkus/quarkus-fs-util/0.0.9/quarkus-fs-util-0.0.9.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/com/github/ben-manes/caffeine/caffeine/3.1.1/caffeine-3.1.1.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/com/google/errorprone/error_prone_annotations/2.14.0/error_prone_annotations-2.14.0.jar!/"
/>
</CLASSES>
<JAVADOC
/>
<SOURCES>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/quarkus/quarkus-caffeine/2.16.5.Final/quarkus-caffeine-2.16.5.Final-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/quarkus/quarkus-core/2.16.5.Final/quarkus-core-2.16.5.Final-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/jakarta/annotation/jakarta.annotation-api/1.3.5/jakarta.annotation-api-1.3.5-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/jakarta/enterprise/jakarta.enterprise.cdi-api/2.0.2/jakarta.enterprise.cdi-api-2.0.2-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/jakarta/el/jakarta.el-api/3.0.3/jakarta.el-api-3.0.3-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/jakarta/interceptor/jakarta.interceptor-api/1.2.5/jakarta.interceptor-api-1.2.5-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/jakarta/ejb/jakarta.ejb-api/3.2.6/jakarta.ejb-api-3.2.6-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/jakarta/transaction/jakarta.transaction-api/1.3.2/jakarta.transaction-api-1.3.2-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/jakarta/inject/jakarta.inject-api/1.0/jakarta.inject-api-1.0-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/quarkus/quarkus-ide-launcher/2.16.5.Final/quarkus-ide-launcher-2.16.5.Final-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/quarkus/quarkus-development-mode-spi/2.16.5.Final/quarkus-development-mode-spi-2.16.5.Final-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/smallrye/config/smallrye-config/2.13.3/smallrye-config-2.13.3-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/smallrye/config/smallrye-config-core/2.13.3/smallrye-config-core-2.13.3-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/eclipse/microprofile/config/microprofile-config-api/2.0.1/microprofile-config-api-2.0.1-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/smallrye/common/smallrye-common-annotation/1.13.2/smallrye-common-annotation-1.13.2-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/smallrye/common/smallrye-common-expression/1.13.2/smallrye-common-expression-1.13.2-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/smallrye/common/smallrye-common-function/1.13.2/smallrye-common-function-1.13.2-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/smallrye/common/smallrye-common-constraint/1.13.2/smallrye-common-constraint-1.13.2-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/smallrye/common/smallrye-common-classloader/1.13.2/smallrye-common-classloader-1.13.2-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/ow2/asm/asm/9.4/asm-9.4-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/smallrye/config/smallrye-config-common/2.13.3/smallrye-config-common-2.13.3-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/jboss/logging/jboss-logging/3.5.0.Final/jboss-logging-3.5.0.Final-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/jboss/logmanager/jboss-logmanager-embedded/1.0.11/jboss-logmanager-embedded-1.0.11-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/jboss/logging/jboss-logging-annotations/2.2.1.Final/jboss-logging-annotations-2.2.1.Final-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/jboss/threads/jboss-threads/3.4.3.Final/jboss-threads-3.4.3.Final-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/jboss/slf4j/slf4j-jboss-logmanager/1.2.0.Final/slf4j-jboss-logmanager-1.2.0.Final-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/graalvm/sdk/graal-sdk/22.3.0/graal-sdk-22.3.0-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/org/wildfly/common/wildfly-common/1.5.4.Final-format-001/wildfly-common-1.5.4.Final-format-001-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/quarkus/quarkus-bootstrap-runner/2.16.5.Final/quarkus-bootstrap-runner-2.16.5.Final-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/smallrye/common/smallrye-common-io/1.13.2/smallrye-common-io-1.13.2-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/github/crac/org-crac/0.1.3/org-crac-0.1.3-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/io/quarkus/quarkus-fs-util/0.0.9/quarkus-fs-util-0.0.9-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/com/github/ben-manes/caffeine/caffeine/3.1.1/caffeine-3.1.1-sources.jar!/"
/>
<root
url=
"jar://$MAVEN_REPOSITORY$/com/google/errorprone/error_prone_annotations/2.14.0/error_prone_annotations-2.14.0-sources.jar!/"
/>
</SOURCES>
</library>
</component>
\ No newline at end of file
Redis.iml
View file @
1d9fb337
...
...
@@ -27,5 +27,6 @@
</library>
</orderEntry>
<orderEntry
type=
"library"
name=
"io.quarkus.junit5.mockito"
level=
"project"
/>
<orderEntry
type=
"library"
name=
"io.quarkus.caffeine"
level=
"project"
/>
</component>
</module>
\ No newline at end of file
src/storage/Cacheable.java
0 → 100644
View file @
1d9fb337
package
storage
;
public
interface
Cacheable
<
K
,
V
>
{
void
save
(
K
key
,
V
value
);
void
save
(
K
key
,
V
value
,
Long
expirationTime
);
V
get
(
K
key
);
void
delete
(
K
key
);
}
src/storage/CaffeineCachePolicy.java
0 → 100644
View file @
1d9fb337
package
storage
;
import
com.github.benmanes.caffeine.cache.Cache
;
import
com.github.benmanes.caffeine.cache.Caffeine
;
import
com.github.benmanes.caffeine.cache.RemovalCause
;
import
java.util.concurrent.TimeUnit
;
import
java.util.logging.Logger
;
public
class
CaffeineCachePolicy
<
K
,
V
>
implements
CachePolicy
<
K
,
V
>
{
private
final
Cache
<
K
,
V
>
cache
;
private
static
final
Logger
logger
=
Logger
.
getLogger
(
CaffeineCachePolicy
.
class
.
getName
());
public
CaffeineCachePolicy
(
int
maxCapacity
)
{
this
.
cache
=
Caffeine
.
newBuilder
()
.
maximumSize
(
maxCapacity
)
.
expireAfterAccess
(
60
,
TimeUnit
.
MINUTES
)
.
evictionListener
((
K
key
,
V
value
,
RemovalCause
cause
)
->
logger
.
info
(
"Evicted key: "
+
key
+
", Value: "
+
value
+
", Reason: "
+
cause
))
.
build
();
}
@Override
public
void
add
(
K
key
,
V
value
)
{
cache
.
put
(
key
,
value
);
}
@Override
public
V
retrieve
(
K
key
)
{
return
cache
.
getIfPresent
(
key
);
}
@Override
public
void
delete
(
K
key
)
{
cache
.
invalidate
(
key
);
}
@Override
public
void
runMaintenance
()
{
cache
.
cleanUp
();
}
}
src/storage/LRUCachePolicy.java
View file @
1d9fb337
src/storage/Storage.java
View file @
1d9fb337
...
...
@@ -2,24 +2,22 @@ package storage;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.logging.Logger
;
public
class
Storage
{
private
final
int
capacity
=
1000000
;
private
static
final
Logger
logger
=
Logger
.
getLogger
(
Storage
.
class
.
getName
());
private
final
CachePolicy
<
String
,
String
>
storage
;
private
final
Map
<
String
,
Long
>
timeToExpiration
=
new
ConcurrentHashMap
<>(
capacity
);
private
final
Map
<
String
,
Long
>
currentTimeForKey
=
new
ConcurrentHashMap
<>(
capacity
);
private
Storage
(
int
threshold
)
{
this
.
storage
=
new
LRUCachePolicy
<>(
capacity
,
threshold
);
private
Storage
()
{
this
.
storage
=
new
CaffeineCachePolicy
<>(
capacity
);
RdbFileReader
<
String
,
String
>
reader
=
new
RdbFileReader
<>();
Map
<
String
,
Long
>
stringStringMap
=
reader
.
getKeysExpiration
();
this
.
timeToExpiration
.
putAll
(
stringStringMap
);
}
private
static
final
class
StorageHolder
{
private
static
final
Storage
instance
=
new
Storage
(
800000
);
private
static
final
Storage
instance
=
new
Storage
();
}
public
static
Storage
getInstance
()
{
...
...
@@ -45,14 +43,6 @@ public class Storage {
}
private
boolean
isExpired
(
String
key
)
{
if
(
timeToExpiration
.
containsKey
(
key
)
&&
!
currentTimeForKey
.
containsKey
(
key
))
{
long
currentTime
=
System
.
currentTimeMillis
();
long
expirationTime
=
timeToExpiration
.
get
(
key
);
if
(
currentTime
>
expirationTime
)
{
logger
.
info
(
"Key expired: "
+
key
);
return
true
;
}
}
if
(
currentTimeForKey
.
containsKey
(
key
))
{
long
currTime
=
System
.
currentTimeMillis
();
long
expirationTime
=
timeToExpiration
.
get
(
key
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment