r41216 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41215‎ | r41216 | r41217 >
Date:07:13, 24 September 2008
Author:tstarling
Status:old
Tags:
Comment:
Allow the stream flushing behaviour to be configured for each processor
Modified paths:
  • /trunk/udplog/debian/changelog (modified) (history)
  • /trunk/udplog/udp2log/LogProcessor.cpp (modified) (history)
  • /trunk/udplog/udp2log/LogProcessor.h (modified) (history)
  • /trunk/udplog/udp2log/Udp2LogConfig.cpp (modified) (history)

Diff [purge]

Index: trunk/udplog/debian/changelog
@@ -1,3 +1,9 @@
 2+udplog (1.4-1) unstable; urgency=low
 3+
 4+ * Allow the stream flushing behaviour to be configured for each processor
 5+
 6+ -- Tim Starling <tstarling@wikimedia.org> Wed, 24 Sep 2008 17:08:46 +1000
 7+
28 udplog (1.3-1) unstable; urgency=low
39
410 * Restart broken pipes after 5 seconds. Because awk dies after days or weeks with EFAULT.
Index: trunk/udplog/udp2log/LogProcessor.cpp
@@ -7,7 +7,7 @@
88 // FileProcessor
99 //---------------------------------------------------------------------------
1010
11 -LogProcessor * FileProcessor::NewFromConfig(char * params)
 11+LogProcessor * FileProcessor::NewFromConfig(char * params, bool flush)
1212 {
1313 char * strFactor = strtok(params, " \t");
1414 if (strFactor == NULL) {
@@ -22,7 +22,7 @@
2323 );
2424 }
2525 char * filename = strtok(NULL, "");
26 - FileProcessor * fp = new FileProcessor(filename, factor);
 26+ FileProcessor * fp = new FileProcessor(filename, factor, flush);
2727 if (!fp->IsOpen()) {
2828 delete fp;
2929 throw ConfigError("Unable to open file");
@@ -35,7 +35,7 @@
3636 {
3737 if (Sample()) {
3838 f.write(buffer, size);
39 - if (factor >= 10) {
 39+ if (flush) {
4040 f.flush();
4141 }
4242 }
@@ -45,7 +45,7 @@
4646 // PipeProcessor
4747 //---------------------------------------------------------------------------
4848
49 -LogProcessor * PipeProcessor::NewFromConfig(char * params)
 49+LogProcessor * PipeProcessor::NewFromConfig(char * params, bool flush)
5050 {
5151 char * strFactor = strtok(params, " \t");
5252 if (strFactor == NULL) {
@@ -60,7 +60,7 @@
6161 );
6262 }
6363 char * command = strtok(NULL, "");
64 - PipeProcessor * pp = new PipeProcessor(command, factor);
 64+ PipeProcessor * pp = new PipeProcessor(command, factor, flush);
6565 if (!pp->IsOpen()) {
6666 delete pp;
6767 throw ConfigError("Unable to open pipe");
@@ -88,7 +88,7 @@
8989 // Reopen it after a few seconds
9090 alarm(RESTART_INTERVAL);
9191 } else {
92 - if (factor >= 10) {
 92+ if (flush) {
9393 fflush(f);
9494 }
9595 }
Index: trunk/udplog/udp2log/Udp2LogConfig.cpp
@@ -39,21 +39,29 @@
4040 type = strtok(line, " \t");
4141 if (!type) {
4242 continue;
43 - } else {
 43+ }
 44+
 45+ params = strtok(NULL, "");
 46+ LogProcessor * processor = NULL;
 47+ bool flush = false;
 48+
 49+ if (!strcmp(type, "flush")) {
 50+ flush = true;
 51+ type = strtok(params, " \t");
4452 params = strtok(NULL, "");
45 - LogProcessor * processor = NULL;
46 - if (!strcmp(type, "file")) {
47 - processor = FileProcessor::NewFromConfig(params);
48 - } else if (!strcmp(type, "pipe")) {
49 - processor = PipeProcessor::NewFromConfig(params);
50 - } else {
51 - throw ConfigError("Unrecognised log type");
52 - }
 53+ }
5354
54 - if (processor) {
55 - newProcessors.push_back(processor);
56 - }
 55+ if (!strcmp(type, "file")) {
 56+ processor = FileProcessor::NewFromConfig(params, flush);
 57+ } else if (!strcmp(type, "pipe")) {
 58+ processor = PipeProcessor::NewFromConfig(params, flush);
 59+ } else {
 60+ throw ConfigError("Unrecognised log type");
5761 }
 62+
 63+ if (processor) {
 64+ newProcessors.push_back(processor);
 65+ }
5866 }
5967
6068 // Swap in the new configuration
Index: trunk/udplog/udp2log/LogProcessor.h
@@ -13,8 +13,8 @@
1414 virtual ~LogProcessor() {}
1515
1616 protected:
17 - LogProcessor(int factor_)
18 - : counter(0), factor(factor_)
 17+ LogProcessor(int factor_, bool flush_)
 18+ : counter(0), factor(factor_), flush(flush_)
1919 {}
2020
2121
@@ -34,16 +34,17 @@
3535
3636 int counter;
3737 int factor;
 38+ bool flush;
3839 };
3940
4041 class FileProcessor : public LogProcessor
4142 {
4243 public:
43 - static LogProcessor * NewFromConfig(char * params);
 44+ static LogProcessor * NewFromConfig(char * params, bool flush);
4445 virtual void ProcessLine(char *buffer, size_t size);
4546
46 - FileProcessor(char * filename, int factor_)
47 - : LogProcessor(factor_)
 47+ FileProcessor(char * filename, int factor_, bool flush_)
 48+ : LogProcessor(factor_, flush_)
4849 {
4950 f.open(filename, std::ios::app | std::ios::out);
5051 }
@@ -58,12 +59,12 @@
5960 class PipeProcessor : public LogProcessor
6061 {
6162 public:
62 - static LogProcessor * NewFromConfig(char * params);
 63+ static LogProcessor * NewFromConfig(char * params, bool flush);
6364 virtual void ProcessLine(char *buffer, size_t size);
6465 virtual void FixIfBroken();
6566
66 - PipeProcessor(char * command_, int factor_)
67 - : LogProcessor(factor_)
 67+ PipeProcessor(char * command_, int factor_, bool flush_)
 68+ : LogProcessor(factor_, flush_)
6869 {
6970 command = strdup(command_);
7071 f = popen(command, "w");