Skip to content

Commit

Permalink
Squashed merge from apple. Prepare for new build container. (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkSh1 authored Jun 4, 2024
1 parent 6fdae36 commit 5e5473b
Show file tree
Hide file tree
Showing 64 changed files with 2,690 additions and 1,137 deletions.
24 changes: 14 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Calculate versions
id: vers
Expand Down Expand Up @@ -49,13 +49,17 @@ jobs:
for: linux
prepare: "debian-based"
build_on: linux
use_image: ghcr.io/owtech/foundationdb-build:6.3.25-5.ow.1
parallel: 3

parallel: 5
image: foundationdb-build:7.1.61-1.ow.image
owner: ${GITHUB_REPOSITORY_OWNER@L}
runs-on: ${{ matrix.run_on }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set building repo
run: |
echo "use_image=ghcr.io/${{matrix.owner}}/${{matrix.image}}" >> "$GITHUB_ENV"
- name: Build
run: |
Expand All @@ -68,7 +72,7 @@ jobs:
--security-opt label=disable \
--mount=type=bind,src=${{github.workspace}},dst=/home/runner/src,readonly \
--mount=type=bind,src=${{github.workspace}}/bld,dst=/home/runner/bld \
${{ matrix.use_image }} \
$use_image \
/home/runner/src/build-scripts/for-${{ matrix.for }}/build-on-${{ matrix.build_on }}.bash \
${{needs.calc_ver.outputs.project_ver}} \
${{needs.calc_ver.outputs.build_ver}} \
Expand All @@ -95,7 +99,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Download the foundationdb distro
uses: actions/download-artifact@v3
Expand Down Expand Up @@ -134,7 +138,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Download the foundationdb distro
uses: actions/download-artifact@v3
Expand All @@ -161,7 +165,7 @@ jobs:
${{github.workspace}}/packaging/docker/build-images-for-owtech.bash \
${{needs.calc_ver.outputs.full_ver}} \
${{github.workspace}}/bld/linux/packages \
ghcr.io/${{ github.repository_owner }}
ghcr.io/${GITHUB_REPOSITORY_OWNER@L}
tests:
needs: [calc_ver, build]
Expand Down Expand Up @@ -227,4 +231,4 @@ jobs:
run: |
podman ps
python3 -m joshua.joshua start --tarball ${{github.workspace}}/correctness-${{needs.calc_ver.outputs.full_ver}}.tar.gz --max-runs ${{ env.N_OF_TESTS }} && \
python3 -m joshua.joshua tail
python3 -m joshua.joshua tail
9 changes: 5 additions & 4 deletions .github/workflows/make-build-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Make a build image

on:
push:
branches: ["ow-build-image*"]
tags: ["*.image"]

jobs:
calc_ver:
Expand All @@ -17,7 +17,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Calculate versions
id: vers
Expand All @@ -26,6 +26,7 @@ jobs:

build-image:
needs: [calc_ver]
permissions: write-all

strategy:
matrix:
Expand All @@ -42,7 +43,7 @@ jobs:
runs-on: ${{ matrix.run_on }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Build an image
run: |
Expand All @@ -59,4 +60,4 @@ jobs:
run: echo "${{ secrets.GITHUB_TOKEN }}" | podman login ghcr.io -u $ --password-stdin

- name: Push image
run: podman push $IMAGE_NAME ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
run: podman push $IMAGE_NAME ghcr.io/${GITHUB_REPOSITORY_OWNER@L}/$IMAGE_NAME
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ else()
endif()

project(foundationdb
VERSION 7.1.51
VERSION 7.1.61
DESCRIPTION "FoundationDB is a scalable, fault-tolerant, ordered key-value store with full ACID transactions."
HOMEPAGE_URL "http://www.foundationdb.org/"
LANGUAGES C CXX ASM)
Expand Down
2 changes: 1 addition & 1 deletion bindings/c/test/unit/third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ExternalProject_Add(
doctest
PREFIX ${CMAKE_BINARY_DIR}/doctest
GIT_REPOSITORY https://github.com/onqtam/doctest.git
GIT_TAG b7c21ec5ceeadb4951b00396fc1e4642dd347e5f # v2.4.9
GIT_TAG ae7a13539fb71f270b87eb2e874fbac80bc8dda2 # v2.4.11
TIMEOUT 10
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
Expand Down
2 changes: 1 addition & 1 deletion bindings/c/test/unit/unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ TEST_CASE("fdb_transaction_get_mapped_range") {

int id = beginId;
for (int i = 0; i < expectSize; i++, id++) {
const auto& [key, value, begin, end, range_results] = result.mkvs[i];
const auto [key, value, begin, end, range_results] = result.mkvs[i];
CHECK(indexEntryKey(id).compare(key) == 0);
CHECK(EMPTY.compare(value) == 0);
CHECK(range_results.size() == SPLIT_SIZE);
Expand Down
4 changes: 2 additions & 2 deletions bindings/go/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

set(SRCS
src/_stacktester/directory.go
src/fdb/directory/allocator.go
Expand All @@ -19,6 +20,7 @@ set(SRCS
src/fdb/tuple/tuple_test.go
src/fdb/database.go
src/fdb/directory/directorySubspace.go
src/fdb/tenant.go
src/fdb/fdb_test.go
src/fdb/snapshot.go)

Expand Down Expand Up @@ -100,8 +102,6 @@ function(build_go_package)
endif()
add_custom_command(OUTPUT ${outfile}
COMMAND ${CMAKE_COMMAND} -E env ${go_env}
${GO_EXECUTABLE} get -d ${GO_IMPORT_PATH}/${BGP_PATH} &&
${CMAKE_COMMAND} -E env ${go_env}
${GO_EXECUTABLE} install ${GO_IMPORT_PATH}/${BGP_PATH}
DEPENDS ${fdb_options_file}
COMMENT "Building ${BGP_NAME}")
Expand Down
35 changes: 22 additions & 13 deletions bindings/go/src/fdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,22 @@ func retryable(wrapped func() (interface{}, error), onError func(Error) FutureNi
}
}

func transact(tr Transaction, f func(Transaction) (interface{}, error)) (interface{}, error) {
wrapped := func() (ret interface{}, e error) {
defer panicToError(&e)

ret, e = f(tr)

if e == nil {
e = tr.Commit().Get()
}

return
}

return retryable(wrapped, tr.OnError)
}

// Transact runs a caller-provided function inside a retry loop, providing it
// with a newly created Transaction. After the function returns, the Transaction
// will be committed automatically. Any error during execution of the function
Expand Down Expand Up @@ -160,6 +176,11 @@ func (d Database) Transact(f func(Transaction) (interface{}, error)) (interface{
return nil, e
}

return transact(tr, f)
}


func readTransact(tr Transaction, f func(ReadTransaction) (interface{}, error)) (interface{}, error) {
wrapped := func() (ret interface{}, e error) {
defer panicToError(&e)

Expand Down Expand Up @@ -203,19 +224,7 @@ func (d Database) ReadTransact(f func(ReadTransaction) (interface{}, error)) (in
return nil, e
}

wrapped := func() (ret interface{}, e error) {
defer panicToError(&e)

ret, e = f(tr)

if e == nil {
e = tr.Commit().Get()
}

return
}

return retryable(wrapped, tr.OnError)
return readTransact(tr, f)
}

// Options returns a DatabaseOptions instance suitable for setting options
Expand Down
4 changes: 4 additions & 0 deletions bindings/go/src/fdb/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ var (
errAPIVersionUnset = Error{2200}
errAPIVersionAlreadySet = Error{2201}
errAPIVersionNotSupported = Error{2203}

errTenantNotFound = Error{2131}
errTenantExists = Error{2132}
errTenantNameInvalid = Error{2134}
)
131 changes: 131 additions & 0 deletions bindings/go/src/fdb/fdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package fdb_test

import (
"bytes"
"fmt"
"testing"

Expand Down Expand Up @@ -311,3 +312,133 @@ func ExamplePrintable() {
fmt.Println(fdb.Printable([]byte{0, 1, 2, 'a', 'b', 'c', '1', '2', '3', '!', '?', 255}))
// Output: \x00\x01\x02abc123!?\xff
}

// Copied from errors.go so that these types aren't public
var (
errTenantNotFound = fdb.Error{2131}
errTenantExists = fdb.Error{2132}
errTenantNameInvalid = fdb.Error{2134}
)

func TestCreateTenant(t *testing.T) {
fdb.MustAPIVersion(710)
db := fdb.MustOpenDefault()

testTenantName := fdb.Key("test-create-tenant")

err := db.CreateTenant(testTenantName)
if err != nil {
t.Fatalf("Unable to create tenant: %v\n", err)
}

_, err = db.OpenTenant(testTenantName)
if err != nil {
t.Fatalf("Unable to open tenant: %v\n", err)
}
}

func TestCreateExistTenant(t *testing.T) {
fdb.MustAPIVersion(710)
db := fdb.MustOpenDefault()

testTenantName := fdb.Key("test-exist-tenant")

err := db.CreateTenant(testTenantName)
if err != nil {
t.Fatalf("Unable to create tenant: %v\n", err)
}

// This should fail
err = db.CreateTenant(testTenantName)
assertErrorCodeEqual(t, err, errTenantExists)
}

/* FIXME: This test will not pass as FDB does not properly return error code TenantNotFound
func TestOpenNotExistTenant(t *testing.T) {
fdb.MustAPIVersion(710)
db := fdb.MustOpenDefault()
testTenantName := fdb.Key("test-not-exist-tenant")
// this should fail
_, err := db.OpenTenant(testTenantName)
assertErrorCodeEqual(t, err, errTenantNotFound)
}
*/

func TestDeleteNotExistTenant(t *testing.T) {
fdb.MustAPIVersion(710)
db := fdb.MustOpenDefault()

testTenantName := fdb.Key("test-not-exist-tenant")

// this should fail
err := db.DeleteTenant(testTenantName)
assertErrorCodeEqual(t, err, errTenantNotFound)
}

func inSlice(sl []fdb.Key, t fdb.Key) bool {
for _, s := range sl {
if bytes.Equal(s, t) {
return true
}
}
return false
}

func assertErrorCodeEqual(t *testing.T, actual error, expected fdb.Error) {
if actual == nil {
t.Fatalf("Error is nil when it should be: %v\n", expected.Code)
}

castErr, ok := actual.(fdb.Error)
if !ok {
t.Fatalf("Error is wrong type %v, expected %v\n", actual, expected)
}

if castErr.Code != expected.Code {
t.Fatalf("Error is wrong code, expected %v, actual %v\n", expected.Code, castErr.Code)
}
}

func TestListTenant(t *testing.T) {
fdb.MustAPIVersion(710)
db := fdb.MustOpenDefault()

testTenantName1 := fdb.Key("1-test-list-1-tenant-1")
testTenantName2 := fdb.Key("2-test-list-2-tenant-2")

err := db.CreateTenant(testTenantName1)
if err != nil {
t.Fatalf("Unable to create tenant 1: %v\n", err)
}

err = db.CreateTenant(testTenantName2)
if err != nil {
t.Fatalf("Unable to create tenant 2: %v\n", err)
}

ls, err := db.ListTenants()
if err != nil {
t.Fatalf("Unable to list tenants: %v\n", err)
}

if !inSlice(ls, testTenantName1) {
t.Fatalf("tenant 1 not in slice %#v", ls)
}

if !inSlice(ls, testTenantName2) {
t.Fatalf("tenant 2 not in slice, %#v", ls)
}
}

func TestInvalidPrefixTenant(t *testing.T) {
fdb.MustAPIVersion(710)
db := fdb.MustOpenDefault()

testTenantName := fdb.Key("\xFFtest-invalid-prefix-tenant")

// this should fail
err := db.CreateTenant(testTenantName)
assertErrorCodeEqual(t, err, errTenantNameInvalid)
}
Loading

0 comments on commit 5e5473b

Please sign in to comment.