MCPcopy Create free account
hub / github.com/apache/mesos / write

Method write

src/slave/container_loggers/logrotate.cpp:195–233  ·  view source on GitHub ↗

Writes the buffer from stdin to the leading log file. When the number of written bytes exceeds `--max_size`, the leading log file is rotated. When the number of log files exceed `--max_files`, the oldest log file is deleted.

Source from the content-addressed store, hash-verified

193 // log file is rotated. When the number of log files exceed `--max_files`,
194 // the oldest log file is deleted.
195 Try<Nothing> write(size_t readSize)
196 {
197 // Rotate the log file if it will grow beyond the `--max_size`.
198 if (bytesWritten + readSize > flags.max_size.bytes()) {
199 rotate();
200 }
201
202 // If the leading log file is not open, open it.
203 // NOTE: We open the file in append-mode as `logrotate` may sometimes fail.
204 if (leading.isNone()) {
205 Try<int> open = os::open(
206 flags.log_filename.get(),
207 O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC,
208 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
209
210 if (open.isError()) {
211 return Error(
212 "Failed to open '" + flags.log_filename.get() +
213 "': " + open.error());
214 }
215
216 leading = open.get();
217 }
218
219 // Write from stdin to `leading`.
220 // NOTE: We do not exit on error here since we are prioritizing
221 // clearing the STDIN pipe (which would otherwise potentially block
222 // the container on write) over log fidelity.
223 Try<Nothing> result =
224 os::write(leading.get(), string(buffer, readSize));
225
226 if (result.isError()) {
227 std::cerr << "Failed to write: " << result.error() << std::endl;
228 }
229
230 bytesWritten += readSize;
231
232 return Nothing();
233 }
234
235 // Calls `logrotate` on the leading log file and resets the `bytesWritten`.
236 void rotate()

Callers 5

_attachContainerInputMethod · 0.45
connectFunction · 0.45
sendMethod · 0.45
foreachFunction · 0.45
foreachFunction · 0.45

Calls 9

NothingClass · 0.85
errorMethod · 0.65
openFunction · 0.50
ErrorFunction · 0.50
writeFunction · 0.50
bytesMethod · 0.45
isNoneMethod · 0.45
getMethod · 0.45
isErrorMethod · 0.45

Tested by

no test coverage detected