Skip to content

Commit 82dd9c7

Browse files
authored
Merge pull request #311 from korpling/comparable-update-events
Fix WAL persistance
2 parents 18b57d2 + e39b1bd commit 82dd9c7

33 files changed

Lines changed: 292 additions & 75 deletions

.github/workflows/release_capi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
omitPrereleaseDuringUpdate: true
7171
deploy_macos_binaries:
7272
if: ${{ github.event.action == 'completed' || github.event.label.name == 'test-release-process' || (github.event_name == 'release' && github.event.action == 'published') }}
73-
runs-on: macos-12
73+
runs-on: macos-14
7474
steps:
7575
- id: latest-release
7676
uses: pozetroninc/github-action-get-latest-release@v0.7.0

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
RUST_LOG: debug
3737
test_mac:
3838
name: Execute automated tests on OSX
39-
runs-on: macos-12
39+
runs-on: macos-14
4040
steps:
4141
- uses: actions/checkout@v2
4242
- uses: actions-rust-lang/setup-rust-toolchain@v1.8.0

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55

66
## [Unreleased]
77

8+
### Added
9+
10+
- `UpdateEvent` now implements `PartialEq` to make possible to compare changes.
11+
12+
### Fixed
13+
14+
- Deserializing a write-ahead log failed because it was located at the wrong
15+
sub-directory and the deserialization routine for the map had a bug.
16+
817
## [3.5.1] - 2024-09-25
918

1019
### Fixed

capi/src/cerror.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct CauseIterator<'a> {
2020
current: Option<&'a dyn StdError>,
2121
}
2222

23-
impl<'a> std::iter::Iterator for CauseIterator<'a> {
23+
impl std::iter::Iterator for CauseIterator<'_> {
2424
type Item = Error;
2525

2626
fn next(&mut self) -> std::option::Option<Error> {

core/Cargo.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,36 @@ bincode = "1.2"
1616
clru = "0.6.1"
1717
itertools = "0.10"
1818
lazy_static = "1.4"
19-
toml = "0.8"
2019
log = "0.4"
2120
memmap2 = "0.9"
2221
normpath = "1.1.1"
2322
num-traits = "0.2"
2423
percent-encoding = "2.1"
2524
quick-xml = "0.28"
26-
rand = { version = "0.8", features = ["small_rng"] }
27-
rayon = { version = "1.3", default-features = false }
25+
rand = {version = "0.8", features = ["small_rng"]}
26+
rayon = {version = "1.3", default-features = false}
2827
regex = "1"
2928
regex-syntax = "0.8"
3029
rustc-hash = "1.0"
31-
serde = { version = "1.0", features = ["rc"] }
30+
serde = {version = "1.0", features = ["rc"]}
3231
serde_bytes = "0.11"
3332
serde_derive = "1.0"
3433
smallvec = "1.6"
35-
smartstring = { version = "1", features = ["serde"] }
34+
smartstring = {version = "1", features = ["serde"]}
3635
sstable = "0.11"
3736
strum = "0.21"
3837
strum_macros = "0.21"
3938
tempfile = "3.1"
4039
thiserror = "1"
40+
toml = "0.8"
4141
transient-btree-index = "0.5"
4242

4343
[target.'cfg(windows)'.dependencies]
44-
winapi = { version = "0.3", features = ["heapapi"] }
44+
winapi = {version = "0.3", features = ["heapapi"]}
4545

4646
[dev-dependencies]
4747
env_logger = "0.9"
4848
fake = "2.2"
49+
insta = {version = "1.38.0", features = ["json"]}
4950
pretty_assertions = "1.3"
51+
serde_json = "1.0"

core/src/dfs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'a> CycleSafeDFS<'a> {
121121
}
122122
}
123123

124-
impl<'a> Iterator for CycleSafeDFS<'a> {
124+
impl Iterator for CycleSafeDFS<'_> {
125125
type Item = Result<DFSStep>;
126126

127127
fn next(&mut self) -> Option<Self::Item> {

core/src/graph/mod.rs

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ impl<CT: ComponentType> Graph<CT> {
626626
std::fs::create_dir_all(&current_path)?;
627627

628628
// If successfull write log
629-
let log_path = location.join("update_log.bin");
629+
let log_path = current_path.join("update_log.bin");
630630

631631
// Create a temporary directory in the same file system as the output
632632
let temporary_dir = tempfile::tempdir_in(&current_path)?;
@@ -1155,4 +1155,62 @@ mod tests {
11551155
db.ensure_loaded_parallel(&[component]).unwrap();
11561156
assert_eq!(0, db.components.len());
11571157
}
1158+
1159+
#[test]
1160+
fn load_with_wal_file() {
1161+
let mut db = Graph::<DefaultComponentType>::new(false).unwrap();
1162+
let example_node = 0;
1163+
db.node_annos
1164+
.insert(
1165+
example_node,
1166+
Annotation {
1167+
key: NODE_TYPE_KEY.as_ref().clone(),
1168+
val: "corpus".into(),
1169+
},
1170+
)
1171+
.unwrap();
1172+
db.node_annos
1173+
.insert(
1174+
example_node,
1175+
Annotation {
1176+
key: NODE_NAME_KEY.as_ref().clone(),
1177+
val: "root".into(),
1178+
},
1179+
)
1180+
.unwrap();
1181+
1182+
let tmp = tempfile::tempdir().unwrap();
1183+
// Save and remember the location, so that updates are recorded in a WAL
1184+
// file
1185+
db.persist_to(tmp.path()).unwrap();
1186+
1187+
// Add an node annotation with apply_update
1188+
let mut u = GraphUpdate::new();
1189+
u.add_event(UpdateEvent::AddNodeLabel {
1190+
node_name: "root".into(),
1191+
anno_ns: "example".into(),
1192+
anno_name: "anno-name".into(),
1193+
anno_value: "anno-value".into(),
1194+
})
1195+
.unwrap();
1196+
db.apply_update(&mut u, |_| {}).unwrap();
1197+
1198+
std::mem::drop(db);
1199+
1200+
// Check that loading the database again contains the changes
1201+
let mut db = Graph::<DefaultComponentType>::new(false).unwrap();
1202+
db.load_from(tmp.path(), true).unwrap();
1203+
let anno_value = db
1204+
.node_annos
1205+
.get_value_for_item(
1206+
&example_node,
1207+
&AnnoKey {
1208+
name: "anno-name".into(),
1209+
ns: "example".into(),
1210+
},
1211+
)
1212+
.unwrap()
1213+
.unwrap();
1214+
assert_eq!("anno-value", anno_value);
1215+
}
11581216
}

core/src/graph/storage/union.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl<'a> UnionEdgeContainer<'a> {
1515
}
1616
}
1717

18-
impl<'a> EdgeContainer for UnionEdgeContainer<'a> {
18+
impl EdgeContainer for UnionEdgeContainer<'_> {
1919
fn get_outgoing_edges<'b>(
2020
&'b self,
2121
node: NodeID,

core/src/graph/update.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use sstable::{SSIterator, Table, TableBuilder, TableIterator};
1515
use tempfile::NamedTempFile;
1616

1717
/// Describes a single update on the graph.
18-
#[derive(Serialize, Deserialize, Clone, Debug)]
18+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
1919
pub enum UpdateEvent {
2020
/// Add a node with a name and type.
2121
AddNode {
@@ -304,10 +304,7 @@ impl<'de> Visitor<'de> for GraphUpdateVisitor {
304304

305305
let mut event_counter = 0;
306306

307-
while let Some((id, event)) = access
308-
.next_entry::<u64, GraphUpdate>()
309-
.map_err(M::Error::custom)?
310-
{
307+
while let Some((id, event)) = access.next_entry::<u64, UpdateEvent>()? {
311308
event_counter = id;
312309
let key = id.create_key();
313310
let value = serialization.serialize(&event).map_err(M::Error::custom)?;
@@ -338,3 +335,6 @@ impl<'de> Deserialize<'de> for GraphUpdate {
338335
deserializer.deserialize_map(GraphUpdateVisitor {})
339336
}
340337
}
338+
339+
#[cfg(test)]
340+
mod tests;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
source: core/src/graph/update/tests.rs
3+
expression: seralized_string
4+
---
5+
{
6+
"1": {
7+
"AddNode": {
8+
"node_name": "parent",
9+
"node_type": "corpus"
10+
}
11+
},
12+
"2": {
13+
"AddNode": {
14+
"node_name": "child",
15+
"node_type": "corpus"
16+
}
17+
},
18+
"3": {
19+
"AddEdge": {
20+
"source_node": "child",
21+
"target_node": "parent",
22+
"layer": "annis",
23+
"component_type": "PartOf",
24+
"component_name": ""
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)