Skip to content

Commit

Permalink
Merge branch '8.5.4-repair' into xcframework
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpablo committed Jan 18, 2024
2 parents a3e7c00 + a685be6 commit 16be7f7
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 5,622 deletions.
4 changes: 4 additions & 0 deletions Code/RocksDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,10 @@ typedef void (^RestoreBlock)(NSError * __autoreleasing *);
- (nullable id)withBulkLoad:(id (NS_NOESCAPE ^)(void))actionBlock
error:(NSError * __autoreleasing *)error;

#pragma mark - Repair

+ (BOOL)repairDB:(NSString *)dbPath options:(RocksDBOptions *)options error:(NSError **)error;

@end

NS_ASSUME_NONNULL_END
15 changes: 15 additions & 0 deletions Code/RocksDB.mm
Original file line number Diff line number Diff line change
Expand Up @@ -804,4 +804,19 @@ - (nullable id)withBulkLoad:(id (NS_NOESCAPE ^)(void))actionBlock
return result;
}

#pragma mark - Repair

+ (BOOL)repairDB:(NSString *)dbPath options:(RocksDBOptions *)options error:(NSError **)error {
rocksdb::Status s = rocksdb::RepairDB(dbPath.UTF8String, options.options);

if (!s.ok()) {
if (error != NULL) {
*error = [RocksDBError errorWithRocksStatus:s];
}
return NO;
}

return YES;
}

@end
2 changes: 2 additions & 0 deletions Code/RocksDBDatabaseOptions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ @interface RocksDBDatabaseOptions ()
#endif
}
@property (nonatomic, assign) const rocksdb::DBOptions options;
@property (nonatomic, strong) RocksDBEnv *env;
@end

@implementation RocksDBDatabaseOptions
Expand Down Expand Up @@ -188,6 +189,7 @@ - (void)setWalRecoveryMode:(RocksDBWALRecoveryMode)walRecoveryMode {
}

- (void)setEnv:(RocksDBEnv*)env {
_env = env;
_options.env = env.env;
}

Expand Down
2 changes: 2 additions & 0 deletions Code/RocksDBEnv.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ NS_ASSUME_NONNULL_BEGIN
- (NSArray<RocksDBThreadStatus *> *)threadList;
#endif

+ (RocksDBEnv*)mock;

@end

NS_ASSUME_NONNULL_END
24 changes: 24 additions & 0 deletions Code/RocksDBEnv.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#import "RocksDBThreadStatus.h"
#import <rocksdb/env.h>
#import <rocksdb/thread_status.h>
#import <rocksdb/utilities/object_registry.h>
#import <rocksdb/utilities/options_type.h>

#pragma mark - Informal Protocols

Expand Down Expand Up @@ -98,4 +100,26 @@ - (NSArray *)threadList
return threadList;
}

#pragma mark - Mock

+ (RocksDBEnv*)mock
{
// 1. Register the built in environments
rocksdb::ConfigOptions options;
rocksdb::Env *dummyEnv = nullptr;
rocksdb::Env::CreateFromString(options, "MockEnv", &dummyEnv);

// 2. Create a new MockEnv
auto envFactory = rocksdb::ObjectLibrary::Default()->FindFactory<rocksdb::Env>("MockEnv");
std::unique_ptr<rocksdb::Env> mockEnvPtr;
std::string errMsg;

envFactory("", &mockEnvPtr, &errMsg);

RocksDBEnv *mock = [RocksDBEnv new];
mock.env = mockEnvPtr.release();

return mock;
}

@end
14 changes: 14 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "lz4-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/goodnotes/lz4-swift",
"state" : {
"revision" : "1711e6db47e500523560fad63b690634c0c790e0",
"version" : "1.9.4"
}
}
],
"version" : 2
}
19 changes: 5 additions & 14 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ let package = Package(
targets: ["ObjectiveRocks"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/goodnotes/lz4-swift", from: "1.9.4")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "ObjectiveRocks",
dependencies: ["RocksDB", "RocksLZ4"],
dependencies: [
"RocksDB",
.product(name: "lz4", package: "lz4-swift")
],
path: "Code",
publicHeadersPath: "./"
),
Expand Down Expand Up @@ -52,17 +54,6 @@ let package = Package(
name: "RocksDB",
url: "https://github.com/GoodNotes/rocksdb/releases/download/v8.10.0/RocksDB.xcframework.zip",
checksum: "70b11dbb039a4e63fc7f4d100c49fb5dbd73db8a5cdefe24b6ee0eb32d1bda39"
),
.target(
name: "RocksLZ4",
path: "lz4",
sources: [
"lz4.c",
"lz4.h",
"lz4hc.c",
"lz4hc.h",
],
publicHeadersPath: "."
)
],
cxxLanguageStandard: .cxx20
Expand Down
Loading

0 comments on commit 16be7f7

Please sign in to comment.