Skip to content

Commit 98c2837

Browse files
committed
Avoid pg_deeplake sync on initdb.
1 parent 0043651 commit 98c2837

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

cpp/deeplake_pg/dl_catalog.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ std::vector<int64_t> load_int64_vector(const nd::array& arr)
128128

129129
int64_t ensure_catalog(const std::string& root_path, icm::string_map<> creds)
130130
{
131+
if (root_path.empty()) {
132+
return 0;
133+
}
131134
const auto tables_path = join_path(root_path, k_tables_name);
132135
const auto columns_path = join_path(root_path, k_columns_name);
133136
const auto indexes_path = join_path(root_path, k_indexes_name);

cpp/deeplake_pg/pg_deeplake.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ void deeplake_xact_callback(XactEvent event, void *arg)
356356
void init_deeplake()
357357
{
358358
static bool initialized = false;
359-
if (initialized) {
359+
if (initialized || !IsUnderPostmaster) {
360360
return;
361361
}
362362
initialized = true;

cpp/deeplake_pg/utils.hpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,17 +270,22 @@ static std::string get_pg_data_directory()
270270
{
271271
const char* data_dir = GetConfigOption("data_directory", true, false);
272272
if (data_dir == nullptr) {
273-
ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("Unable to retrieve data_directory")));
273+
return "";
274274
}
275275
return std::string(data_dir);
276276
}
277277

278278
static std::string get_deeplake_root_directory()
279279
{
280-
static const std::string root_dir_variable_name = "DEEPLAKE_ROOT_PATH";
281-
static const std::string pg_data_dir = get_pg_data_directory();
282-
static const std::string deeplake_root_dir = base::getenv<std::string>(root_dir_variable_name, pg_data_dir);
283-
return deeplake_root_dir;
280+
// Avoid static locals: if get_pg_data_directory() previously failed via
281+
// ereport(ERROR) (longjmp through C++ static init), the static guard
282+
// variable is permanently poisoned and subsequent calls return "".
283+
// Re-evaluate every time so a later call can succeed once GUCs are ready.
284+
auto root = base::getenv<std::string>("DEEPLAKE_ROOT_PATH", "");
285+
if (root.empty()) {
286+
root = get_pg_data_directory();
287+
}
288+
return root;
284289
}
285290

286291
inline std::pair<BlockNumber, OffsetNumber> row_number_to_tid(int64_t row_number)

0 commit comments

Comments
 (0)