Skip to content

Commit f77f35d

Browse files
author
Tris Forster
committed
Fixed possible dataloss on crash during enqueue issue
1 parent 5248ee3 commit f77f35d

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

Diff for: ConcurrentFIFO.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,14 @@ function enqueue($data) {
153153
$index = array('start' => self::INDEX_SIZE, 'end' => self::INDEX_SIZE, 'len' => 0);
154154
}
155155

156-
$this->_write_index($index['start'], $index['end'] + $c + self::LENGTH_SIZE, $index['len'] + 1);
157156
fseek($this->fp, $index['end']);
158157

159158
// write length followed by data
160159
fwrite($this->fp, pack(self::LENGTH_FORMAT, $c), self::LENGTH_SIZE);
161160
fwrite($this->fp, $data, $c);
162161

162+
$this->_write_index($index['start'], $index['end'] + $c + self::LENGTH_SIZE, $index['len'] + 1);
163+
163164
//echo "Wrote {$data} at {$index['end']}\n";
164165
// release lock
165166
flock($this->fp, LOCK_UN);
@@ -307,4 +308,4 @@ function __toString() {
307308
return "<FIFO: {$this->filename}>";
308309
}
309310

310-
}
311+
}

Diff for: RedisQueues.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?
1+
<?php
22
require_once "ConcurrentFIFO.php";
33

44
/**

Diff for: bench.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
define('LOOP', 10000);
3+
define('LOOP', 100000);
44
define('TEST_FIFO', 'test.fifo');
55

66
include "ConcurrentFIFO.php";

Diff for: tests/RedisTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ function testUsage() {
3333
$this->assertSame('test2', $this->redis->rpop('list2'));
3434
}
3535

36-
}
36+
}

0 commit comments

Comments
 (0)