Commit 50f08894 authored by Paal Kvamme's avatar Paal Kvamme
Browse files

More consistency checks when opening a file on the cloud for update.

parent 89d96b9e
......@@ -882,6 +882,36 @@ public:
const InternalZGY::IHistHeaderAccess& hh = this->_meta->hh();
if (hh.samplecount() == 0 || hh.minvalue() > hh.maxvalue())
this->_dirty = true;
// Consistency checks: Only files uploaded by OpenZGY can be updated.
// See also the consistency checks in the SeismicStoreFileDelayedWrite
// constructor regarding the segment size.
if (_fd->xx_iscloud()) {
const std::int64_t headersize = this->_meta_rw->flushMeta(nullptr);
const std::shared_ptr<const FileStatistics> fs = filestats();
const std::vector<std::int64_t> segsizes = fs->segmentSizes();
if (segsizes.size() != 0) {
if (fs->dataStart() >= 0 && fs->dataStart() < segsizes[0]) {
// One or more bricks or tiles were found in the first segment.
// Most likely the file was uploaded by sdutil in a single chunk,
// or it may have been written by the old ZGY-Cloud.
// Distinguishing those two is not always possible because
// ZGY-Cloud can also put everything in the same segment.
throw Errors::ZgyUserError
("Only files uploaded by OpenZGY can be updated.");
}
if (headersize != segsizes[0]) {
// Even when there is no data in the header area, the header
// segment must be exactly the expected size. Most likely
// this is a file containing no data and uploaded by sdutil
// or the old ZGY-Cloud. If there is more than one segment
// or eof is > headersize then there is something weird going on.
// Probably not useful to report on that case though.
throw Errors::ZgyUserError
("Only files uploaded by OpenZGY can be updated. Bad Header size.");
}
}
}
}
/**
......
......@@ -2296,9 +2296,16 @@ ZgyInternalMeta::initFromReopen(const ZgyInternalWriterArgs& args_in, bool compr
}
}
void
/**
* Store metadata on file and return the number of bytes written,
* including padding. Pass a null file for a dry run that only reports
* the size. The dry run may be used as a consistency check when
* opening a file on the cloud for update.
*/
std::int64_t
ZgyInternalMeta::flushMeta(const std::shared_ptr<FileADT>& file)
{
std::int64_t bytes_written{0};
const std::int64_t alignto = this->_ih->bytesperbrick();
IHeaderAccess::podbytes_t slbuf = this->_ih->calculate_write(); // sets _pod._slbufsize
......@@ -2328,7 +2335,8 @@ ZgyInternalMeta::flushMeta(const std::shared_ptr<FileADT>& file)
throw OpenZGY::Errors::ZgyInternalError("Header size mismatch on write");
const IOffsetHeaderAccess& oh = *this->_oh;
if (!(oh.infoff() == (std::int64_t)(bytes[0].size() + bytes[0].size()) &&
if ( (oh.infoff() == (std::int64_t)(bytes[0].size() + bytes[1].size()) &&
oh.stroff() == oh.infoff() + oh.infsize() &&
//oh.histoff() == oh.stroff() + oh.strsize() &&
oh.alphalupoff() == oh.histoff() + oh.histsize() &&
......@@ -2349,9 +2357,12 @@ ZgyInternalMeta::flushMeta(const std::shared_ptr<FileADT>& file)
std::copy(it.begin(), it.end(), std::back_inserter(allbytes));
const std::int64_t paddedsize = ((allbytes.size() + alignto - 1) / alignto) * alignto;
allbytes.resize(paddedsize, 0);
ErrorsWillCorruptFile watchdog(this);
file->xx_write(allbytes.data(), 0, allbytes.size(), UsageHint::Header);
watchdog.disarm();
if (file) {
ErrorsWillCorruptFile watchdog(this);
file->xx_write(allbytes.data(), 0, allbytes.size(), UsageHint::Header);
watchdog.disarm();
}
bytes_written = allbytes.size();
}
else {
// Headers are not contiguous. This should never happen for
......@@ -2359,6 +2370,7 @@ ZgyInternalMeta::flushMeta(const std::shared_ptr<FileADT>& file)
// (which I will never be able to test).
throw OpenZGY::Errors::ZgyInternalError("Headers not contiguous on write");
}
return bytes_written;
}
void
......
......@@ -474,7 +474,7 @@ public:
_loggerfn = logger;
return old;
}
void flushMeta(const std::shared_ptr<FileADT>& file);
std::int64_t flushMeta(const std::shared_ptr<FileADT>& file);
private:
bool _logger(int priority, const std::string& ss = std::string()) const;
bool _logger(int priority, const std::ios& ss) const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment