|
| 1 | +# GeaFlow Store API |
| 2 | + |
| 3 | +GeaFlow Store API provides a unified storage interface for managing state data in graph computing. |
| 4 | +This document introduces how to use and implement these storage interfaces. |
| 5 | + |
| 6 | +## Core Interfaces |
| 7 | + |
| 8 | +GeaFlow Store API includes the following core interfaces: |
| 9 | + |
| 10 | +### IStoreBuilder |
| 11 | + |
| 12 | +Interface for building storage instances. Main methods: |
| 13 | + |
| 14 | +- `getStoreDesc()`: Get storage description |
| 15 | +- `build()`: Build storage instance |
| 16 | + |
| 17 | +### IBaseStore |
| 18 | + |
| 19 | +The base interface for all storage implementations, defining basic storage operations: |
| 20 | + |
| 21 | +- `init()`: Initialize storage |
| 22 | +- `flush()`: Flush data to storage |
| 23 | +- `close()`: Close storage connection |
| 24 | + |
| 25 | +### IStatefulStore |
| 26 | + |
| 27 | +State management storage interface, inheriting from IBaseStore, providing stateful management |
| 28 | +operations: |
| 29 | + |
| 30 | +- `archive()`: Archive current state |
| 31 | +- `recovery()`: Recover state from specified position |
| 32 | +- `recoveryLatest()`: Recover latest version state |
| 33 | +- `compact()`: Compress/merge historical states |
| 34 | +- `drop()`: Drop all data |
| 35 | + |
| 36 | +### IGraphStore |
| 37 | + |
| 38 | +Graph data storage interface, inheriting from IStatefulStore, used for storing graph vertices and |
| 39 | +edges: |
| 40 | + |
| 41 | +- `addVertex()`: Add vertex |
| 42 | +- `getVertex()`: Get vertex |
| 43 | +- `addEdge()`: Add edge |
| 44 | +- `getEdges()`: Get edges |
| 45 | +- `getOneDegreeGraph()`: Get one degree Graph. |
| 46 | + |
| 47 | +## Usage Examples |
| 48 | + |
| 49 | +### Basic Graph Storage Example |
| 50 | + |
| 51 | +```java |
| 52 | +// 1. Create StoreBuilder |
| 53 | +IStoreBuilder builder = new MemoryStoreBuilder(); |
| 54 | + |
| 55 | +// 2. Build storage instance |
| 56 | +IGraphStore graphStore = (IGraphStore) builder.build(); |
| 57 | + |
| 58 | +// 3. Initialize storage |
| 59 | +graphStore.init(context); |
| 60 | + |
| 61 | +// 4. Use storage |
| 62 | +// Add vertex |
| 63 | +graphStore.addVertex(vertex); |
| 64 | + |
| 65 | +// Get vertex |
| 66 | +IVertex vertex = graphStore.getVertex(vertexId); |
| 67 | + |
| 68 | +// Add edge |
| 69 | +graphStore.addEdge(edge); |
| 70 | + |
| 71 | +// Get edges |
| 72 | +List<IEdge> edges = graphStore.getEdges(vertexId); |
| 73 | + |
| 74 | +// 5. Close storage |
| 75 | +graphStore.close(); |
| 76 | +``` |
| 77 | + |
| 78 | +### State Management Example |
| 79 | + |
| 80 | +```java |
| 81 | +// 1. Create stateful storage instance |
| 82 | +IStatefulStore statefulStore = new MemoryStatefulStore(); |
| 83 | + |
| 84 | +// 2. Initialize |
| 85 | +statefulStore.init(context); |
| 86 | + |
| 87 | +// 3. State management operations |
| 88 | +// Archive current state |
| 89 | +statefulStore.archive(); |
| 90 | + |
| 91 | +// Recover from specific version |
| 92 | +statefulStore.recovery(version); |
| 93 | + |
| 94 | +// Compact historical states |
| 95 | +statefulStore.compact(version); |
| 96 | + |
| 97 | +// 4. Close storage |
| 98 | +statefulStore.close(); |
| 99 | +``` |
| 100 | + |
| 101 | +## Implementing Custom Storage |
| 102 | + |
| 103 | +To implement custom storage, you need to: |
| 104 | + |
| 105 | +1. Implement `IStoreBuilder` interface to create storage builder |
| 106 | +2. Implement corresponding storage interfaces based on requirements: |
| 107 | + - Basic storage: implement `IBaseStore` |
| 108 | + - State management storage: implement `IStatefulStore` |
| 109 | + - Graph data storage: implement `IGraphStore` |
| 110 | +3. Configure SPI service in `resources/META-INF/services` |
| 111 | + |
| 112 | +For examples, refer to implementations in `geaflow-store-memory` module: |
| 113 | + |
| 114 | +- `MemoryStoreBuilder` |
| 115 | +- `StaticGraphMemoryStore` |
| 116 | + |
| 117 | +## Configuration |
| 118 | + |
| 119 | +Specify storage implementation and related parameters through configuration: |
| 120 | + |
| 121 | +```java |
| 122 | +Configuration conf = new Configuration(); |
| 123 | +// Specify storage type |
| 124 | +conf.put(StoreConfig.STORE_TYPE, "memory"); |
| 125 | + |
| 126 | +// State management configurations |
| 127 | +conf.put(StoreConfig.STATE_RETENTION_TIME, "24h"); // State retention time |
| 128 | +conf.put(StoreConfig.COMPACT_INTERVAL, "6h"); // State compaction interval |
| 129 | + |
| 130 | +// Other storage related configurations |
0 commit comments