wgtmac commented on code in PR #1893:
URL: https://github.com/apache/orc/pull/1893#discussion_r1574667774
##########
c++/src/Timezone.cc:
##########
@@ -691,12 +683,68 @@ namespace orc {
try {
std::unique_ptr<InputStream> file = readFile(filename);
size_t size = static_cast<size_t>(file->getLength());
- std::vector<unsigned char> buffer(size);
+ buffer.resize(size);
file->read(&buffer[0], size, 0);
- timezoneCache[filename] = std::make_shared<TimezoneImpl>(filename,
buffer);
} catch (ParseError& err) {
throw TimezoneError(err.what());
}
+ return buffer;
+ }
+
+ class LazyTimezone : public Timezone {
+ private:
+ std::string filename_;
+ mutable std::unique_ptr<TimezoneImpl> impl_;
+ mutable std::atomic<bool> initialized_;
+
+ TimezoneImpl* getImpl() const {
+ if (!initialized_) {
+ std::lock_guard<std::mutex> timezone_lock(timezone_mutex);
Review Comment:
`timezone_mutex` is used to guard `TimezoneImpl::timezoneCache`. Should we
use a much finer-grained mutex which is per LazyTimezone instance?
##########
c++/src/Timezone.cc:
##########
@@ -691,12 +683,68 @@ namespace orc {
try {
std::unique_ptr<InputStream> file = readFile(filename);
size_t size = static_cast<size_t>(file->getLength());
- std::vector<unsigned char> buffer(size);
+ buffer.resize(size);
file->read(&buffer[0], size, 0);
- timezoneCache[filename] = std::make_shared<TimezoneImpl>(filename,
buffer);
} catch (ParseError& err) {
throw TimezoneError(err.what());
}
+ return buffer;
+ }
+
+ class LazyTimezone : public Timezone {
+ private:
+ std::string filename_;
+ mutable std::unique_ptr<TimezoneImpl> impl_;
+ mutable std::atomic<bool> initialized_;
+
+ TimezoneImpl* getImpl() const {
+ if (!initialized_) {
+ std::lock_guard<std::mutex> timezone_lock(timezone_mutex);
+ if (!initialized_) {
+ auto buffer = loadTZDB(filename_);
+ impl_.reset(new TimezoneImpl(filename_, std::move(buffer)));
Review Comment:
```suggestion
impl_ = std::make_unique<TimezoneImpl>(filename_,
std::move(buffer));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]