Skip to content

Commit

Permalink
a minimal fix for presenting issue, but several SetFinalizer time-bom…
Browse files Browse the repository at this point in the history
…bs remain. fixes apple#11856
  • Loading branch information
Jason E. Aten, Ph.D. committed Jan 1, 2025
1 parent 63035b5 commit dab3519
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
13 changes: 12 additions & 1 deletion bindings/go/src/fdb/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ type Tenant struct {
db Database
}

// Close releases the local handle/resources associated
// with the tenant; it does not affect the
// tenant's existance or the data it owns at all.
// Client programs should arrange to call Close()
// when they are done with the Tenant. Often
// this can be done conveniently in a defer statement
// right after OpenTenant.
func (t *Tenant) Close() {
t.destroy()
}

type tenant struct {
ptr *C.FDBTenant
}
Expand All @@ -169,7 +180,7 @@ func (d Database) OpenTenant(name KeyConvertible) (Tenant, error) {
}

tnt := &tenant{outt}
runtime.SetFinalizer(tnt, (*tenant).destroy)
//runtime.SetFinalizer(tnt, (*tenant).destroy)

return Tenant{tnt, d}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmake/CompileBoost.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function(compile_boost)

set(BOOST_INSTALL_DIR "${CMAKE_BINARY_DIR}/boost_install")
ExternalProject_add("${COMPILE_BOOST_TARGET}Project"
URL "https://boostorg.jfrog.io/artifactory/main/release/1.78.0/source/boost_1_78_0.tar.bz2"
URL "https://sourceforge.net/projects/boost/files/boost/1.78.0/boost_1_78_0.tar.bz2/download"
URL_HASH SHA256=8681f175d4bdb26c52222665793eef08490d7758529330f98d3b29dd0735bccc
CONFIGURE_COMMAND ${BOOTSTRAP_COMMAND}
${BOOTSTRAP_ARGS}
Expand Down
15 changes: 13 additions & 2 deletions fdbclient/include/fdbclient/ThreadSafeTransaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "fdbclient/ClusterInterface.h"
#include "fdbclient/IClientApi.h"
#include "fdbclient/ISingleThreadTransaction.h"
#include <iostream>

// An implementation of IDatabase that serializes operations onto the network thread and interacts with the lower-level
// client APIs exposed by NativeAPI and ReadYourWrites.
Expand All @@ -53,8 +54,18 @@ class ThreadSafeDatabase : public IDatabase, public ThreadSafeReferenceCounted<T
// cluster file therefore is valid, but the database might be unavailable.
ThreadFuture<Void> onConnected();

void addref() override { ThreadSafeReferenceCounted<ThreadSafeDatabase>::addref(); }
void delref() override { ThreadSafeReferenceCounted<ThreadSafeDatabase>::delref(); }
void addref() override {
int oldCount = this->referenceCount;
ThreadSafeReferenceCounted<ThreadSafeDatabase>::addref();
std::cout << "ThreadSafeDatabase refcount increased: " << oldCount << " -> " << this->referenceCount
<< " (this: " << this << ")" << std::endl;
}
void delref() override {
int oldCount = this->referenceCount; // noticed alternative? debugGetReferenceCount()
ThreadSafeReferenceCounted<ThreadSafeDatabase>::delref();
std::cout << "ThreadSafeDatabase refcount decreased: " << oldCount << " -> " << this->referenceCount
<< " (this: " << this << ")" << std::endl;
}

ThreadFuture<int64_t> rebootWorker(const StringRef& address, bool check, int duration) override;
ThreadFuture<Void> forceRecoveryWithDataLoss(const StringRef& dcid) override;
Expand Down
4 changes: 3 additions & 1 deletion flow/include/flow/FastRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <atomic>
#include <cstdint>
#include "flow/Traceable.h"
#include <iostream>

// The thread safety this class provides is that it's safe to call addref and
// delref on the same object concurrently in different threads. Subclass does
Expand Down Expand Up @@ -53,10 +54,11 @@ class ThreadSafeReferenceCounted {
void setrefCountUnsafe(int32_t count) const { referenceCount.store(count); }
int32_t debugGetReferenceCount() const { return referenceCount.load(); }

mutable std::atomic<int32_t> referenceCount;

private:
ThreadSafeReferenceCounted(const ThreadSafeReferenceCounted&) /* = delete*/;
void operator=(const ThreadSafeReferenceCounted&) /* = delete*/;
mutable std::atomic<int32_t> referenceCount;
};

template <class Subclass>
Expand Down

0 comments on commit dab3519

Please sign in to comment.