Skip to content

Commit

Permalink
Remove leftover storage on table creation
Browse files Browse the repository at this point in the history
* Have initdb -f destroy default disk cache location; also error on table creation if there is pre-cached data in the disk cache for the new table.
  • Loading branch information
misiugodfrey authored and andrewseidl committed Jun 4, 2021
1 parent 15233f7 commit cc07f50
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Catalog/Catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,14 @@ void Catalog::createTable(
}

try {
auto cache = dataMgr_->getPersistentStorageMgr()->getDiskCache();
if (cache) {
CHECK(!cache->hasCachedMetadataForKeyPrefix({getCurrentDB().dbId, td.tableId}))
<< "Disk cache at " + cache->getCacheDirectory()
<< " contains preexisting data for new table. Please "
"delete or clear cache before continuing";
}

addTableToMap(&td, cds, dds);
calciteMgr_->updateMetadata(currentDB_.dbName, td.tableName);
if (!td.storageType.empty() && td.storageType != StorageType::FOREIGN_TABLE) {
Expand Down
17 changes: 17 additions & 0 deletions Tests/CommandLineTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,28 @@ TEST_F(InitDBTest, AlreadyInit) {
"OmniSci catalogs already initialized at " + get_temp_dir() +
". Use -f to force reinitialization.");
}
// Blocked by existing cache.
TEST_F(InitDBTest, ExistingCache) {
boost::filesystem::create_directory(get_temp_dir() + "/omnisci_disk_cache");
CommandLineTestcase(get_executable(),
get_temp_dir(),
1,
"",
"OmniSci disk cache already exists at " + get_temp_dir() +
"/omnisci_disk_cache" + ". Use -f to force reinitialization.");
}
// Override existing database.
TEST_F(InitDBTest, Force) {
CommandLineTestcase(get_executable(), get_temp_dir(), 0, "", "");
CommandLineTestcase(get_executable(), get_temp_dir() + " -f", 0, "", "");
}
// Override existing cache
TEST_F(InitDBTest, ForceCache) {
boost::filesystem::create_directory(get_temp_dir() + "/omnisci_disk_cache");
boost::filesystem::create_directory(get_temp_dir() + "/omnisci_disk_cache/temp");
CommandLineTestcase(get_executable(), get_temp_dir() + " -f", 0, "", "");
ASSERT_FALSE(boost::filesystem::exists(get_temp_dir() + "/omnisci_disk_cache/temp"));
}
// Data directory does not exist.
TEST_F(InitDBTest, MissingDir) {
CommandLineTestcase(get_executable(),
Expand Down
1 change: 1 addition & 0 deletions Tests/ForeignTableDmlTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "DBHandlerTestHelpers.h"
#include "DataMgr/ForeignStorage/ForeignStorageCache.h"
#include "DataMgr/ForeignStorage/ForeignTableRefresh.h"
#include "DataMgrTestHelpers.h"
#include "Geospatial/Types.h"
#include "ImportExport/DelimitedParserUtils.h"
#include "TestHelpers.h"
Expand Down
10 changes: 10 additions & 0 deletions initdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ int main(int argc, char* argv[]) {
return 1;
}
}
std::string disk_cache_path = base_path + "/omnisci_disk_cache";
if (boost::filesystem::exists(disk_cache_path)) {
if (force) {
boost::filesystem::remove_all(disk_cache_path);
} else {
std::cerr << "OmniSci disk cache already exists at " + disk_cache_path +
". Use -f to force reinitialization.\n";
return 1;
}
}
if (!boost::filesystem::create_directory(catalogs_path)) {
std::cerr << "Cannot create mapd_catalogs subdirectory under " << base_path
<< std::endl;
Expand Down

0 comments on commit cc07f50

Please sign in to comment.