dbms: ignore missing files [#METR-10242]

This commit is contained in:
Pavel Kartavyy 2014-03-05 23:39:34 +04:00
parent 774206e517
commit 5bc75d93b5

View File

@ -1304,6 +1304,9 @@ void StorageMergeTree::alter(const ASTAlterQuery::Parameters & params)
DEFAULT_MERGE_BLOCK_SIZE, column_name, *this, part, ranges, StoragePtr(), false, NULL, ""), expr);
MergedColumnOnlyOutputStream out(*this, full_path + part->name + '/', true);
out.writePrefix();
try
{
while(DB::Block b = in.read())
{
/// оставляем только столбец с результатом
@ -1313,39 +1316,54 @@ void StorageMergeTree::alter(const ASTAlterQuery::Parameters & params)
LOG_TRACE(log, "Write Suffix");
out.writeSuffix();
}
catch (const Exception & e)
{
if (e.code() != ErrorCodes::ALL_REQUESTED_COLUMNS_ARE_MISSING)
throw;
}
}
/// переименовываем файлы
/// переименовываем старые столбцы, добавляя расширение .old
for (DataPartPtr & part : parts)
{
std::string path = full_path + part->name + '/' + escapeForFileName(name_type.name);
if (Poco::File(path + ".bin").exists())
{
LOG_TRACE(log, "Renaming " << path + ".bin" << " to " << path + ".bin" + ".old");
Poco::File(path + ".bin").renameTo(path + ".bin" + ".old");
LOG_TRACE(log, "Renaming " << path + ".mrk" << " to " << path + ".mrk" + ".old");
Poco::File(path + ".mrk").renameTo(path + ".mrk" + ".old");
}
}
/// переименовываем временные столбцы
for (DataPartPtr & part : parts)
{
std::string path = full_path + part->name + '/' + escapeForFileName(out_column);
std::string new_path = full_path + part->name + '/' + escapeForFileName(name_type.name);
if (Poco::File(path + ".bin").exists())
{
LOG_TRACE(log, "Renaming " << path + ".bin" << " to " << new_path + ".bin");
Poco::File(path + ".bin").renameTo(new_path + ".bin");
LOG_TRACE(log, "Renaming " << path + ".mrk" << " to " << new_path + ".mrk");
Poco::File(path + ".mrk").renameTo(new_path + ".mrk");
}
}
// удаляем старые столбцы
for (DataPartPtr & part : parts)
{
std::string path = full_path + part->name + '/' + escapeForFileName(name_type.name);
if (Poco::File(path + ".bin" + ".old").exists())
{
LOG_TRACE(log, "Removing old column " << path + ".bin" + ".old");
Poco::File(path + ".bin" + ".old").remove();
LOG_TRACE(log, "Removing old column " << path + ".mrk" + ".old");
Poco::File(path + ".mrk" + ".old").remove();
}
}
}
context.getUncompressedCache()->reset();
context.getMarkCache()->reset();
}