Skip to content

Commit 16be7f7

Browse files
committed
Merge branch '8.5.4-repair' into xcframework
2 parents a3e7c00 + a685be6 commit 16be7f7

File tree

11 files changed

+66
-5622
lines changed

11 files changed

+66
-5622
lines changed

Code/RocksDB.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,10 @@ typedef void (^RestoreBlock)(NSError * __autoreleasing *);
590590
- (nullable id)withBulkLoad:(id (NS_NOESCAPE ^)(void))actionBlock
591591
error:(NSError * __autoreleasing *)error;
592592

593+
#pragma mark - Repair
594+
595+
+ (BOOL)repairDB:(NSString *)dbPath options:(RocksDBOptions *)options error:(NSError **)error;
596+
593597
@end
594598

595599
NS_ASSUME_NONNULL_END

Code/RocksDB.mm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,4 +804,19 @@ - (nullable id)withBulkLoad:(id (NS_NOESCAPE ^)(void))actionBlock
804804
return result;
805805
}
806806

807+
#pragma mark - Repair
808+
809+
+ (BOOL)repairDB:(NSString *)dbPath options:(RocksDBOptions *)options error:(NSError **)error {
810+
rocksdb::Status s = rocksdb::RepairDB(dbPath.UTF8String, options.options);
811+
812+
if (!s.ok()) {
813+
if (error != NULL) {
814+
*error = [RocksDBError errorWithRocksStatus:s];
815+
}
816+
return NO;
817+
}
818+
819+
return YES;
820+
}
821+
807822
@end

Code/RocksDBDatabaseOptions.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ @interface RocksDBDatabaseOptions ()
2828
#endif
2929
}
3030
@property (nonatomic, assign) const rocksdb::DBOptions options;
31+
@property (nonatomic, strong) RocksDBEnv *env;
3132
@end
3233

3334
@implementation RocksDBDatabaseOptions
@@ -188,6 +189,7 @@ - (void)setWalRecoveryMode:(RocksDBWALRecoveryMode)walRecoveryMode {
188189
}
189190

190191
- (void)setEnv:(RocksDBEnv*)env {
192+
_env = env;
191193
_options.env = env.env;
192194
}
193195

Code/RocksDBEnv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ NS_ASSUME_NONNULL_BEGIN
4646
- (NSArray<RocksDBThreadStatus *> *)threadList;
4747
#endif
4848

49+
+ (RocksDBEnv*)mock;
50+
4951
@end
5052

5153
NS_ASSUME_NONNULL_END

Code/RocksDBEnv.mm

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#import "RocksDBThreadStatus.h"
1212
#import <rocksdb/env.h>
1313
#import <rocksdb/thread_status.h>
14+
#import <rocksdb/utilities/object_registry.h>
15+
#import <rocksdb/utilities/options_type.h>
1416

1517
#pragma mark - Informal Protocols
1618

@@ -98,4 +100,26 @@ - (NSArray *)threadList
98100
return threadList;
99101
}
100102

103+
#pragma mark - Mock
104+
105+
+ (RocksDBEnv*)mock
106+
{
107+
// 1. Register the built in environments
108+
rocksdb::ConfigOptions options;
109+
rocksdb::Env *dummyEnv = nullptr;
110+
rocksdb::Env::CreateFromString(options, "MockEnv", &dummyEnv);
111+
112+
// 2. Create a new MockEnv
113+
auto envFactory = rocksdb::ObjectLibrary::Default()->FindFactory<rocksdb::Env>("MockEnv");
114+
std::unique_ptr<rocksdb::Env> mockEnvPtr;
115+
std::string errMsg;
116+
117+
envFactory("", &mockEnvPtr, &errMsg);
118+
119+
RocksDBEnv *mock = [RocksDBEnv new];
120+
mock.env = mockEnvPtr.release();
121+
122+
return mock;
123+
}
124+
101125
@end

Package.resolved

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ let package = Package(
1313
targets: ["ObjectiveRocks"]),
1414
],
1515
dependencies: [
16-
// Dependencies declare other packages that this package depends on.
17-
// .package(url: /* package url */, from: "1.0.0"),
16+
.package(url: "https://github.com/goodnotes/lz4-swift", from: "1.9.4")
1817
],
1918
targets: [
2019
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
2120
// Targets can depend on other targets in this package, and on products in packages this package depends on.
2221
.target(
2322
name: "ObjectiveRocks",
24-
dependencies: ["RocksDB", "RocksLZ4"],
23+
dependencies: [
24+
"RocksDB",
25+
.product(name: "lz4", package: "lz4-swift")
26+
],
2527
path: "Code",
2628
publicHeadersPath: "./"
2729
),
@@ -52,17 +54,6 @@ let package = Package(
5254
name: "RocksDB",
5355
url: "https://github.com/GoodNotes/rocksdb/releases/download/v8.10.0/RocksDB.xcframework.zip",
5456
checksum: "70b11dbb039a4e63fc7f4d100c49fb5dbd73db8a5cdefe24b6ee0eb32d1bda39"
55-
),
56-
.target(
57-
name: "RocksLZ4",
58-
path: "lz4",
59-
sources: [
60-
"lz4.c",
61-
"lz4.h",
62-
"lz4hc.c",
63-
"lz4hc.h",
64-
],
65-
publicHeadersPath: "."
6657
)
6758
],
6859
cxxLanguageStandard: .cxx20

0 commit comments

Comments
 (0)