Skip to content

Commit cda2b43

Browse files
author
Wang, Gang(Gary)
committed
MNEMONIC-327: Provide a feature set for durable memory services
1 parent fe9b538 commit cda2b43

File tree

9 files changed

+108
-3
lines changed

9 files changed

+108
-3
lines changed

mnemonic-core/src/main/java/org/apache/mnemonic/NonVolatileMemAllocator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
package org.apache.mnemonic;
1919

20-
import java.nio.ByteBuffer;
20+
import org.apache.mnemonic.service.memoryservice.MemoryServiceFeature;
2121
import org.apache.mnemonic.service.memoryservice.NonVolatileMemoryAllocatorService;
2222
import org.flowcomputing.commons.resgc.ResCollector;
2323
import org.flowcomputing.commons.resgc.ResReclaim;
2424

25+
import java.nio.ByteBuffer;
26+
2527
/**
2628
* manage a big native persistent memory pool through libpmalloc.so provided by
2729
* pmalloc project.
@@ -60,6 +62,9 @@ public NonVolatileMemAllocator(NonVolatileMemoryAllocatorService nvmasvc, long c
6062
if (null == nvmasvc) {
6163
throw new IllegalArgumentException("NonVolatileMemoryAllocatorService object is null");
6264
}
65+
if (!nvmasvc.getFeatures().contains(MemoryServiceFeature.NONVOLATILE)) {
66+
throw new ConfigurationException("The specified memory service does not support non-volatile feature");
67+
}
6368
if (isnew && capacity <= 0) {
6469
throw new IllegalArgumentException("NonVolatileMemAllocator cannot be initialized with capacity <= 0.");
6570
}

mnemonic-core/src/main/java/org/apache/mnemonic/VolatileMemAllocator.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717

1818
package org.apache.mnemonic;
1919

20-
import java.nio.ByteBuffer;
21-
20+
import org.apache.mnemonic.service.memoryservice.MemoryServiceFeature;
2221
import org.apache.mnemonic.service.memoryservice.VolatileMemoryAllocatorService;
2322
import org.flowcomputing.commons.resgc.ResCollector;
2423
import org.flowcomputing.commons.resgc.ResReclaim;
2524

25+
import java.nio.ByteBuffer;
26+
2627
/**
2728
* manage a big native memory pool through libvmem.so that is provied by Intel
2829
* nvml library.
@@ -57,6 +58,9 @@ public VolatileMemAllocator(VolatileMemoryAllocatorService vmasvc, long capacity
5758
if (null == vmasvc) {
5859
throw new IllegalArgumentException("VolatileMemoryAllocatorService object is null");
5960
}
61+
if (!vmasvc.getFeatures().contains(MemoryServiceFeature.VOLATILE)) {
62+
throw new ConfigurationException("The specified memory service does not support volatile feature");
63+
}
6064
if (capacity <= 0) {
6165
throw new IllegalArgumentException("VolatileMemAllocator cannot be initialized with capacity <= 0.");
6266
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.mnemonic.service.memoryservice;
18+
19+
public enum MemoryServiceFeature {
20+
21+
VOLATILE(1),
22+
NONVOLATILE(2),
23+
TRANSACTABLE(3),
24+
QUERYABLE(4);
25+
26+
private int value;
27+
28+
MemoryServiceFeature(int val) {
29+
this.value = val;
30+
}
31+
32+
public int getValue() {
33+
return value;
34+
}
35+
36+
}

mnemonic-core/src/main/java/org/apache/mnemonic/service/memoryservice/VolatileMemoryAllocatorService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.mnemonic.service.memoryservice;
1919

2020
import java.nio.ByteBuffer;
21+
import java.util.Set;
2122

2223
public interface VolatileMemoryAllocatorService {
2324

@@ -297,4 +298,11 @@ public interface VolatileMemoryAllocatorService {
297298
*/
298299
boolean isInTransaction();
299300

301+
/**
302+
* provide a set of features that the memory service can offer
303+
*
304+
* @return a set of features that supported by this memory service
305+
*/
306+
Set<MemoryServiceFeature> getFeatures();
307+
300308
}

mnemonic-memory-services/mnemonic-java-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/JavaVMemServiceImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.mnemonic.service.memoryservice.internal;
1919

2020
import org.apache.mnemonic.ConfigurationException;
21+
import org.apache.mnemonic.service.memoryservice.MemoryServiceFeature;
2122
import org.apache.mnemonic.service.memoryservice.VolatileMemoryAllocatorService;
2223

2324
import java.io.File;
@@ -29,6 +30,8 @@
2930
import java.util.Collections;
3031
import java.util.HashMap;
3132
import java.util.Map;
33+
import java.util.Set;
34+
import java.util.HashSet;
3235

3336
public class JavaVMemServiceImpl implements VolatileMemoryAllocatorService {
3437

@@ -219,6 +222,13 @@ public boolean isInTransaction() {
219222
throw new UnsupportedOperationException("Not support transaction");
220223
}
221224

225+
@Override
226+
public Set<MemoryServiceFeature> getFeatures() {
227+
Set<MemoryServiceFeature> ret = new HashSet<MemoryServiceFeature>();
228+
ret.add(MemoryServiceFeature.VOLATILE);
229+
return ret;
230+
}
231+
222232
public Map<Long, Long> getMInfo() {
223233
return this.m_info;
224234
}

mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMemServiceImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717

1818
package org.apache.mnemonic.service.memoryservice.internal;
1919

20+
import org.apache.mnemonic.service.memoryservice.MemoryServiceFeature;
2021
import org.apache.mnemonic.service.memoryservice.NonVolatileMemoryAllocatorService;
2122
import org.flowcomputing.commons.primitives.NativeLibraryLoader;
2223

2324
import java.nio.ByteBuffer;
25+
import java.util.HashSet;
26+
import java.util.Set;
2427

2528
public class PMemServiceImpl implements NonVolatileMemoryAllocatorService {
2629
static {
@@ -161,6 +164,14 @@ public boolean isInTransaction() {
161164
throw new UnsupportedOperationException("Not support transaction");
162165
}
163166

167+
@Override
168+
public Set<MemoryServiceFeature> getFeatures() {
169+
Set<MemoryServiceFeature> ret = new HashSet<MemoryServiceFeature>();
170+
ret.add(MemoryServiceFeature.VOLATILE);
171+
ret.add(MemoryServiceFeature.NONVOLATILE);
172+
return ret;
173+
}
174+
164175
protected native long ninit(long capacity, String uri, boolean isnew);
165176

166177
protected native void nclose(long id);

mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/VMemServiceImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@
1717

1818
package org.apache.mnemonic.service.memoryservice.internal;
1919

20+
import org.apache.mnemonic.service.memoryservice.MemoryServiceFeature;
2021
import org.apache.mnemonic.service.memoryservice.VolatileMemoryAllocatorService;
2122
import org.flowcomputing.commons.primitives.NativeLibraryLoader;
2223

2324
import java.nio.ByteBuffer;
2425
import java.util.Collections;
2526
import java.util.HashMap;
2627
import java.util.Map;
28+
import java.util.Set;
29+
import java.util.HashSet;
2730

2831
public class VMemServiceImpl implements VolatileMemoryAllocatorService {
2932
static {
@@ -154,6 +157,13 @@ public boolean isInTransaction() {
154157
throw new UnsupportedOperationException("Not support transaction");
155158
}
156159

160+
@Override
161+
public Set<MemoryServiceFeature> getFeatures() {
162+
Set<MemoryServiceFeature> ret = new HashSet<MemoryServiceFeature>();
163+
ret.add(MemoryServiceFeature.VOLATILE);
164+
return ret;
165+
}
166+
157167
protected native long ninit(long capacity, String uri, boolean isnew);
158168

159169
protected native void nclose(long id);

mnemonic-memory-services/mnemonic-pmalloc-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMallocServiceImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717

1818
package org.apache.mnemonic.service.memoryservice.internal;
1919

20+
import org.apache.mnemonic.service.memoryservice.MemoryServiceFeature;
2021
import org.apache.mnemonic.service.memoryservice.NonVolatileMemoryAllocatorService;
2122
import org.flowcomputing.commons.primitives.NativeLibraryLoader;
2223

2324
import java.nio.ByteBuffer;
25+
import java.util.HashSet;
26+
import java.util.Set;
2427

2528
public class PMallocServiceImpl implements NonVolatileMemoryAllocatorService {
2629
static {
@@ -161,6 +164,14 @@ public boolean isInTransaction() {
161164
throw new UnsupportedOperationException("Not support transaction");
162165
}
163166

167+
@Override
168+
public Set<MemoryServiceFeature> getFeatures() {
169+
Set<MemoryServiceFeature> ret = new HashSet<MemoryServiceFeature>();
170+
ret.add(MemoryServiceFeature.VOLATILE);
171+
ret.add(MemoryServiceFeature.NONVOLATILE);
172+
return ret;
173+
}
174+
164175
protected native long ninit(long capacity, String uri, boolean isnew);
165176

166177
protected native void nclose(long id);

mnemonic-memory-services/mnemonic-sys-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/SysVMemServiceImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@
1717

1818
package org.apache.mnemonic.service.memoryservice.internal;
1919

20+
import org.apache.mnemonic.service.memoryservice.MemoryServiceFeature;
2021
import org.apache.mnemonic.service.memoryservice.VolatileMemoryAllocatorService;
2122
import org.flowcomputing.commons.primitives.NativeLibraryLoader;
2223

2324
import java.nio.ByteBuffer;
2425
import java.util.Collections;
2526
import java.util.HashMap;
2627
import java.util.Map;
28+
import java.util.Set;
29+
import java.util.HashSet;
2730

2831
public class SysVMemServiceImpl implements VolatileMemoryAllocatorService {
2932
static {
@@ -154,6 +157,13 @@ public boolean isInTransaction() {
154157
throw new UnsupportedOperationException("Not support transaction");
155158
}
156159

160+
@Override
161+
public Set<MemoryServiceFeature> getFeatures() {
162+
Set<MemoryServiceFeature> ret = new HashSet<MemoryServiceFeature>();
163+
ret.add(MemoryServiceFeature.VOLATILE);
164+
return ret;
165+
}
166+
157167
protected native long ninit(long capacity, String uri, boolean isnew);
158168

159169
protected native void nclose(long id);

0 commit comments

Comments
 (0)