Giter VIP home page Giter VIP logo

fdbswift's People

Contributors

dimitribouniol avatar kirilltitov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

fdbswift's Issues

Migrate to FoundationDB 6

We need to make sure that everything is working correctly with recently released major version of database. Hopefully, no changes and version bump needed

Implement own precondition function for all assertions

Stdlib precondition fails silently in release builds, which is nonsense. We should migrate all precondition calls to a new function

public func _precondition(
    _ condition: @autoclosure () -> Bool,
    _ message: @autoclosure () -> String = String(),
    file: StaticString = #file, line: UInt = #line
) {
    guard condition() == true else {
        fatalError("Precondition failed: \(message())", file: file, line: line)
    }
}

Support for version stamps in keys

Is there any interest in adding support for 80-bit and 96-bit Versionstamps to Tuple? The .setVersionstampedKey option is already there, so all that would need to be done is to add a type code for version stamps, and a check in Transaction.atomic(_:key:value:) to look for a single Versionstamp type, and append it's position within the key to the end of the key's byte string.

If you are fine with the addition, I'd be more than happy to submit a PR for this, since I've found a need for it.

Implement Directory layer

That's an oof, because I don't really understand how to port it from Python or Go, because it utilizes [blocking, obviously] mutexes heavily, and it's not quite clear

  1. Why use them
  2. How to use them [in Swift-NIO context]

Appendix:

  1. High-level documentation: https://apple.github.io/foundationdb/developer-guide.html#directories
  2. Python implementation: https://github.com/apple/foundationdb/blob/master/bindings/python/fdb/directory_impl.py
  3. Go implementation: https://github.com/apple/foundationdb/blob/master/bindings/go/src/fdb/directory/allocator.go

`'foundationdb/fdb_c.h' file not found` when building in Xcode

I'm trying to play around with FDB in a simple Vapor project, but I'm having trouble getting started. Specifically, when building with Xcode, I get the following errors:

<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "shim.h"
        ^
/Users/dimitribouniol/Library/Developer/Xcode/DerivedData/hello-bfiigegfzdngdvepisiicspgaxaf/SourcePackages/checkouts/FDBSwift/Sources/CFDB/shim.h:5:14: error: 'foundationdb/fdb_c.h' file not found
    #include "foundationdb/fdb_c.h"
             ^
/Users/dimitribouniol/Library/Developer/Xcode/DerivedData/hello-bfiigegfzdngdvepisiicspgaxaf/SourcePackages/checkouts/FDBSwift/Sources/FDB/FDB.swift:3:8: error: could not build Objective-C module 'CFDB'
import CFDB
       ^

This is my Package.swift:

// swift-tools-version:5.2
import PackageDescription

let package = Package(
    name: "hello",
    platforms: [
       .macOS(.v10_15)
    ],
    dependencies: [
        // 💧 A server-side Swift web framework.
        .package(url: "https://github.com/vapor/vapor.git", from: "4.0.0-rc"),
        .package(url: "https://github.com/kirilltitov/FDBSwift.git", from: "4.0.0")
    ],
    targets: [
        .target(
            name: "App",
            dependencies: [
                .product(name: "Vapor", package: "vapor"),
                .product(name: "FDB", package: "FDBSwift")
            ],
            swiftSettings: [
                // Enable better optimizations when building in Release configuration. Despite the use of
                // the `.unsafeFlags` construct required by SwiftPM, this flag is recommended for Release
                // builds. See <https://github.com/swift-server/guides#building-for-production> for details.
                .unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))
            ]
        ),
        .target(name: "Run", dependencies: [.target(name: "App")]),
        .testTarget(name: "AppTests", dependencies: [
            .target(name: "App"),
            .product(name: "XCTVapor", package: "vapor"),
        ])
    ]
)

Is there something obvious that I'm missing? Things seem to build via swift build (the process of which I'm fairly unfamiliar with), but not in Xcode. I did make sure to install the pkgconfig:
image

No License

I just noticed there there is no license for this repo. Could one be added?

Safer Tuple unpack

Should not cause runtime error if invalid bytes are passed, instead gentle error should be thrown.

FDBTuplePackable's methods' names and definitions are too wide

Currently FDB extends builtin types like Bool, Int etc with method pack() (and _pack()) as per FDBTuplePackable protocol.

This naming is too wide, whereas it should be FDB-specific. Proposed naming is getPackedFDBTupleValue (and a respective underscored method).

Now that I think of it, do we really need these methods as methods? Can't we just stick with [computed] vars? Methods aren't throwing, and I really can't recall why did I define the protocol the way I defined it. Vars can still be inlinable...

This change should land either in v5, or in v4 with deprecating (obsoleting?) existing implementation.

Issues running tests with Xcode 12

I'm not sure if anyone else (👋 @kirilltitov) has run into this, but I cannot run tests when the package is built using Xcode 12. The following errors are reported, indicating the test target cannot find libfdb_c.dylib:

2020-10-08 12:43:14.476787-0700 xctest[82265:4451631] The bundle “FDBTests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
2020-10-08 12:43:14.476968-0700 xctest[82265:4451631] (dlopen_preflight(/Users/dimitribouniol/Library/Developer/Xcode/DerivedData/FDBSwift-avmdmjjucugpndfvczrsqjfgiexd/Build/Products/Debug/FDBTests.xctest/Contents/MacOS/FDBTests): Library not loaded: libfdb_c.dylib
  Referenced from: /Users/dimitribouniol/Library/Developer/Xcode/DerivedData/FDBSwift-avmdmjjucugpndfvczrsqjfgiexd/Build/Products/Debug/FDBTests.xctest/Contents/MacOS/FDBTests
  Reason: image not found)
Program ended with exit code: 82

This extends to packages that depend on FDBSwift. Running the tests via SwiftPM (Swift 5.3) directly runs the tests fine. Building and running an app that depends on FDBSwift via Xcode also works fine.

I initially though this could have something to do with systemLibrary support in SwiftPM, so I made a bare-bones package that imported libfdb, and saw the same issues. However, switching the library to libevent (A random pkgConfig I had installed on my system) built and ran the tests fine, so I think it may be specific to the fdb pkgConfig?

Here is the libevent.pc:

#libevent pkg-config source file

prefix=/usr/local/Cellar/libevent/2.1.11_1
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: libevent
Description: libevent is an asynchronous notification event loop library
Version: 2.1.11-stable
Requires:
Conflicts:
Libs: -L${libdir} -levent
Libs.private: 
Cflags: -I${includedir}

Compared to my libfdb.pc:

prefix=/usr/local
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib

Name: fdb
Description: FoundationDB macOS library
Version: 6.2.22
Cflags: -I${includedir}
Libs: -L${libdir} -lfdb_c

I'd appreciate any pointers if it seems I'm doing something wrong, or if this is reproducible at all...

Transaction `set` is ambiguous.

I am trying transactions using the simple set (no future) from Sources/FDB/Transaction/Transaction+Sync.swift line 14 that says
func set(key: AnyFDBKey, value: Bytes, commit: Bool) throws {
but I am getting an Ambiguous use of 'set(key:value:commit:)' because Sources/FDB/Transaction/Transaction+NIO.swift line 45 has the same method signature with a different result
func set(key: AnyFDBKey, value: Bytes, commit: Bool) -> EventLoopFuture<AnyFDBTransaction> {

The tests that are in the repository import FDB in as @testable and uses internal methods, so they are no help. Any help would be valuable.

Some tests pollute the local cluster

testStringKeys() and testStaticStringKeys() both add a key/value foo to the local cluster, but don't clean them up. Should these have been in the test's subspace instead?

func testStringKeys() throws {
let fdb = FDBTests.fdb!
let key = "foo"
let value: Bytes = [0, 1, 2]
XCTAssertNoThrow(try fdb.set(key: key, value: value))
XCTAssertEqual(try fdb.get(key: key), value)
}
func testStaticStringKeys() throws {
let fdb = FDBTests.fdb!
let key: StaticString = "foo"
let value: Bytes = [0, 1, 2]
XCTAssertNoThrow(try fdb.set(key: key, value: value))
XCTAssertEqual(try fdb.get(key: key), value)
}

Even more verbose

Verbose mode should be really verbose (additional attention to connection process). Probably adopt official Swift Server Logger.

Why not use an additional package instead of requiring manual installation steps

The official swift bindings seem to use an additional package (https://github.com/FoundationDB/fdb-swift-c-packaging) to handle importing the C API on various platforms — although I understand not using the official repos (they haven't been updated for 2 years, and don't have tagged releases for specific FDB versions), is there a reason this library doesn't use the same approach? I imagine it would make maintaining future versions and re-installation on new systems a lot easier.

Async interface

Hi,

thanks for the heads up on apple/foundationdb#204. I see you already have the async interface on your ToDo list. I would recommend to primarily focus on the async interface. For synchronous access a simple wait() function should be fine.

Swift NIO has a great concept for asynchronous futures and the first web-frameworks adapt this concept (e.g. Vapor 3).

Would it be possible to have Swift NIO style Futures and Promises?

Thanks!

Proper namespace

Everything should start from FDB: FDB.Transaction, FDB.Tuple etc. Exceptions: protocols (damn it) — TuplePackable >> FDBTuplePackable until Swift allows proper nested types or enables proper namespaces.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.