Skip to content

Commit 3e6e6c3

Browse files
authored
Improve object file store logging (#849)
1 parent 62c20ed commit 3e6e6c3

File tree

4 files changed

+74
-11
lines changed

4 files changed

+74
-11
lines changed

src/lib/object_store/Directory.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ bool Directory::refresh()
108108

109109
if (dir == NULL)
110110
{
111-
DEBUG_MSG("Failed to open directory %s", path.c_str());
111+
ERROR_MSG("Failed to open directory %s (%s)", path.c_str(), strerror(errno));
112112

113113
return false;
114114
}
@@ -168,6 +168,10 @@ bool Directory::refresh()
168168
DEBUG_MSG("File not used %s", name.c_str());
169169
}
170170
}
171+
else
172+
{
173+
WARNING_MSG("Failed to stat %s (%s)", fullPath.c_str(), strerror(errno));
174+
}
171175
}
172176
}
173177

@@ -192,7 +196,7 @@ bool Directory::refresh()
192196
if (errno == ENOENT)
193197
goto finished;
194198

195-
DEBUG_MSG("Failed to open directory %s", path.c_str());
199+
ERROR_MSG("Failed to open directory %s (%s)", path.c_str(), strerror(errno));
196200

197201
return false;
198202
}
@@ -218,6 +222,8 @@ bool Directory::refresh()
218222

219223
valid = true;
220224

225+
DEBUG_MSG("Directory %s refreshed: %zu files, %zu subdirs", path.c_str(), files.size(), subDirs.size());
226+
221227
return true;
222228
}
223229

@@ -255,10 +261,16 @@ bool Directory::rmdir(std::string name, bool doRefresh /* = false */)
255261

256262
#ifndef _WIN32
257263
if (::rmdir(fullPath.c_str()) != 0)
264+
{
265+
ERROR_MSG("Failed to remove directory %s (%s)", fullPath.c_str(), strerror(errno));
258266
return false;
267+
}
259268
#else
260269
if (_rmdir(fullPath.c_str()) != 0)
270+
{
271+
ERROR_MSG("Failed to remove directory %s (%s)", fullPath.c_str(), strerror(errno));
261272
return false;
273+
}
262274
#endif
263275
if (doRefresh)
264276
return refresh();
@@ -271,9 +283,19 @@ bool Directory::remove(std::string name)
271283
std::string fullPath = path + OS_PATHSEP + name;
272284

273285
#ifndef _WIN32
274-
return (!::remove(fullPath.c_str()) && refresh());
286+
if (::remove(fullPath.c_str()) != 0)
287+
{
288+
ERROR_MSG("Failed to remove file %s (%s)", fullPath.c_str(), strerror(errno));
289+
return false;
290+
}
291+
return refresh();
275292
#else
276-
return (!_unlink(fullPath.c_str()) && refresh());
293+
if (_unlink(fullPath.c_str()) != 0)
294+
{
295+
ERROR_MSG("Failed to remove file %s (%s)", fullPath.c_str(), strerror(errno));
296+
return false;
297+
}
298+
return refresh();
277299
#endif
278300
}
279301

src/lib/object_store/Generation.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ bool Generation::wasUpdated()
9696

9797
if (!genFile.isValid())
9898
{
99+
WARNING_MSG("Generation::wasUpdated: could not open %s; assuming updated", path.c_str());
99100
return true;
100101
}
101102

@@ -105,11 +106,13 @@ bool Generation::wasUpdated()
105106

106107
if (!genFile.readULong(onDisk))
107108
{
109+
WARNING_MSG("Generation::wasUpdated: could not read %s; assuming updated", path.c_str());
108110
return true;
109111
}
110112

111113
if (onDisk != currentValue)
112114
{
115+
DEBUG_MSG("Generation::wasUpdated: %s changed %lu -> %lu", path.c_str(), currentValue, onDisk);
113116
currentValue = onDisk;
114117
return true;
115118
}
@@ -122,6 +125,7 @@ bool Generation::wasUpdated()
122125

123126
if (!objectFile.isValid())
124127
{
128+
WARNING_MSG("Generation::wasUpdated: could not open %s; assuming updated", path.c_str());
125129
return true;
126130
}
127131

@@ -131,9 +135,15 @@ bool Generation::wasUpdated()
131135

132136
if (!objectFile.readULong(onDisk))
133137
{
138+
WARNING_MSG("Generation::wasUpdated: could not read %s; assuming updated", path.c_str());
134139
return true;
135140
}
136141

142+
if (onDisk != currentValue)
143+
{
144+
DEBUG_MSG("Generation::wasUpdated: %s changed %lu -> %lu", path.c_str(), currentValue, onDisk);
145+
}
146+
137147
return (onDisk != currentValue);
138148
}
139149
}
@@ -155,6 +165,7 @@ void Generation::commit()
155165

156166
if (!genFile.isValid())
157167
{
168+
WARNING_MSG("Generation::commit: could not open %s for writing", path.c_str());
158169
return;
159170
}
160171

@@ -175,6 +186,8 @@ void Generation::commit()
175186

176187
genFile.unlock();
177188

189+
DEBUG_MSG("Generation::commit: initialized %s to %lu", path.c_str(), currentValue);
190+
178191
return;
179192
}
180193

@@ -202,6 +215,12 @@ void Generation::commit()
202215
currentValue = onDisk;
203216

204217
pendingUpdate = false;
218+
219+
DEBUG_MSG("Generation::commit: %s committed generation %lu", path.c_str(), currentValue);
220+
}
221+
else
222+
{
223+
WARNING_MSG("Generation::commit: failed to update %s", path.c_str());
205224
}
206225

207226
genFile.unlock();

src/lib/object_store/OSToken.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ OSToken::OSToken(const std::string inTokenPath, int inUmask)
6262
tokenMutex = MutexFactory::i()->getMutex();
6363
valid = (gen != NULL) && (tokenMutex != NULL) && tokenDir->isValid() && tokenObject->valid;
6464

65-
DEBUG_MSG("Opened token %s", tokenPath.c_str());
65+
DEBUG_MSG("Opened token %s (valid=%d)", tokenPath.c_str(), valid);
6666

6767
index(true);
6868
}
@@ -596,9 +596,18 @@ bool OSToken::index(bool isFirstTime /* = false */)
596596
}
597597

598598
// Check the integrity
599-
if (!tokenDir->refresh() || !tokenObject->valid)
599+
if (!tokenDir->refresh())
600600
{
601-
ERROR_MSG("Token integrity check failed");
601+
ERROR_MSG("Failed to refresh token directory %s", tokenPath.c_str());
602+
603+
valid = false;
604+
605+
return false;
606+
}
607+
608+
if (!tokenObject->valid)
609+
{
610+
ERROR_MSG("Token object is not valid for %s", tokenPath.c_str());
602611

603612
valid = false;
604613

@@ -658,8 +667,13 @@ bool OSToken::index(bool isFirstTime /* = false */)
658667

659668
currentFiles = newSet;
660669

661-
DEBUG_MSG("%d objects were added and %d objects were removed", addedFiles.size(), removedFiles.size());
662-
DEBUG_MSG("Current directory set contains %d objects", currentFiles.size());
670+
DEBUG_MSG("%zu objects were added and %zu objects were removed", addedFiles.size(), removedFiles.size());
671+
DEBUG_MSG("Current directory set contains %zu objects", currentFiles.size());
672+
673+
if (!removedFiles.empty())
674+
{
675+
WARNING_MSG("Token %s: %zu object(s) no longer on disk", tokenPath.c_str(), removedFiles.size());
676+
}
663677

664678
// Now update the set of objects
665679

@@ -709,14 +723,16 @@ bool OSToken::index(bool isFirstTime /* = false */)
709723
}
710724
else
711725
{
726+
WARNING_MSG("Token %s: invalidating object %s (file no longer present)",
727+
tokenPath.c_str(), fileObject->getFilename().c_str());
712728
fileObject->invalidate();
713729
}
714730
}
715731

716732
// Set the new objects
717733
objects = newObjects;
718734

719-
DEBUG_MSG("The token now contains %d objects", objects.size());
735+
DEBUG_MSG("The token now contains %zu objects", objects.size());
720736

721737
return true;
722738
}

src/lib/object_store/ObjectFile.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ bool ObjectFile::isValid()
275275
// been deleted.
276276
void ObjectFile::invalidate()
277277
{
278+
DEBUG_MSG("Object %s invalidated", path.c_str());
279+
278280
valid = false;
279281

280282
discardAttributes();
@@ -678,7 +680,7 @@ void ObjectFile::store(bool isCommit /* = false */)
678680

679681
if (!objectFile.isValid())
680682
{
681-
DEBUG_MSG("Cannot open object %s for writing", path.c_str());
683+
ERROR_MSG("Cannot open object %s for writing", path.c_str());
682684

683685
valid = false;
684686

@@ -693,6 +695,8 @@ void ObjectFile::store(bool isCommit /* = false */)
693695

694696
if (!writeAttributes(objectFile))
695697
{
698+
ERROR_MSG("Failed to write attributes to object %s", path.c_str());
699+
696700
valid = false;
697701

698702
return;
@@ -702,6 +706,8 @@ void ObjectFile::store(bool isCommit /* = false */)
702706
{
703707
if (!writeAttributes(objectFile))
704708
{
709+
ERROR_MSG("Failed to commit attributes to object %s", path.c_str());
710+
705711
valid = false;
706712

707713
return;

0 commit comments

Comments
 (0)