[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] gzz/lava gzz/storm/util/DiffBlock.java gzz/stor...
From: |
Benja Fallenstein |
Subject: |
[Gzz-commits] gzz/lava gzz/storm/util/DiffBlock.java gzz/stor... |
Date: |
Sat, 18 Jan 2003 18:56:37 -0500 |
CVSROOT: /cvsroot/gzz
Module name: gzz
Changes by: Benja Fallenstein <address@hidden> 03/01/18 18:56:36
Modified files:
lava/gzz/storm/util: DiffBlock.java DiffingStormFiler.java
SimpleStormFiler.java VersionBlock.java
lava/test/gzz/storm: StormPoolTest.java
lava/test/gzz/storm/util: StormFilerBlock.test
Added files:
lava/test/gzz/storm/util: DiffingStormFiler.test
SimpleStormFiler.test StormFiler.meta
Log message:
More-- I get a VERY weird error now
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/util/DiffBlock.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/util/DiffingStormFiler.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/util/SimpleStormFiler.java.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/util/VersionBlock.java.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/storm/StormPoolTest.java.diff?tr1=1.14&tr2=1.15&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/storm/util/DiffingStormFiler.test?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/storm/util/SimpleStormFiler.test?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/storm/util/StormFiler.meta?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/storm/util/StormFilerBlock.test.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
Patches:
Index: gzz/lava/gzz/storm/util/DiffBlock.java
diff -u gzz/lava/gzz/storm/util/DiffBlock.java:1.3
gzz/lava/gzz/storm/util/DiffBlock.java:1.4
--- gzz/lava/gzz/storm/util/DiffBlock.java:1.3 Sat Jan 18 17:09:39 2003
+++ gzz/lava/gzz/storm/util/DiffBlock.java Sat Jan 18 18:56:36 2003
@@ -32,12 +32,20 @@
in.close();
}
- public BlockId getFromId() throws IOException {
- return BlockId.getMediaserverId(header.get("X-Gzz-Diff-From"));
+ public BlockId getFromId() throws MoreThanOneElementException {
+ try {
+ return BlockId.getMediaserverId(header.get("X-Gzz-Diff-From"));
+ } catch(NoSuchElementException e) {
+ return null;
+ }
}
- public BlockId getToId() throws IOException {
- return BlockId.getMediaserverId(header.get("X-Gzz-Diff-To"));
+ public BlockId getToId() throws MoreThanOneElementException {
+ try {
+ return BlockId.getMediaserverId(header.get("X-Gzz-Diff-To"));
+ } catch(NoSuchElementException e) {
+ return null;
+ }
}
public void writeTo(OutputStream out) throws IOException {
Index: gzz/lava/gzz/storm/util/DiffingStormFiler.java
diff -u gzz/lava/gzz/storm/util/DiffingStormFiler.java:1.3
gzz/lava/gzz/storm/util/DiffingStormFiler.java:1.4
--- gzz/lava/gzz/storm/util/DiffingStormFiler.java:1.3 Tue Jan 14 12:21:51 2003
+++ gzz/lava/gzz/storm/util/DiffingStormFiler.java Sat Jan 18 18:56:36 2003
@@ -20,7 +20,94 @@
}
- // XXX
+ public VersionBlock load(BlockId id) throws IOException {
+ try {
+ return super.load(id);
+ } catch(FileNotFoundException _) {
+ Set diffs = index.getDiffBlocksTo(id, format);
+ System.out.println("ndiffs: "+diffs.size());
+ for(Iterator i=diffs.iterator(); i.hasNext();) {
+ try {
+ DiffBlock diffBlock = (DiffBlock)i.next();
+ VersionBlock fromBlock = load(diffBlock.getFromId());
+ Version from = fromBlock.version;
+ Version to = diffBlock.diff.applyTo(from);
+ VersionBlock toBlock =
+ new VersionBlock(diffBlock.headerTo, to, format);
+ toBlock.checkId(id);
+
+ return toBlock;
+ } catch(IOException e) {
+ System.err.println("Exception while loading diff: "+e);
+ System.err.println("Ignore.");
+ }
+ }
+
+ throw new FileNotFoundException("No valid diff path to "+id+"
found");
+ }
+ }
+
+
+ public void save(Version toVersion) throws IOException {
+ if(current == null) {
+ // First version -> no diff
+ saveVersion(toVersion);
+ return;
+ }
+
+ BlockId fromId = current.getTarget();
+ VersionBlock fromVersionBlock = load(fromId);
+ Version fromVersion = fromVersionBlock.version;
+ if(fromVersion.equals(toVersion)) return;
+
+ Block toBlock = saveVersion(toVersion);
+ VersionBlock toVersionBlock = new VersionBlock(toBlock, format);
+ BlockId toId = toBlock.getId();
+
+ Block diffStormBlock = saveDiff(fromVersionBlock, fromId,
+ toVersionBlock, toId);
+
+ DiffBlock diffBlock = new DiffBlock(diffStormBlock, format);
+ Version reconstructed = diffBlock.diff.applyTo(fromVersion);
+
+ VersionBlock versionBlock =
+ new VersionBlock(diffBlock.headerTo, reconstructed, format);
+
+ try {
+ versionBlock.checkId(toBlock.getId());
+ pool.delete(toBlock);
+ } catch(BlockId.WrongIdException e) {
+ System.err.println("======= correct ======= ("+toBlock.getId()+")");
+
System.err.println(CopyUtil.readString(toBlock.getRawInputStream()));
+ System.err.println("======= wrong =======");
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ versionBlock.writeTo(out);
+ System.err.println(new String(out.toByteArray()));
+ System.err.println("=======================");
+ System.err.println("verify...");
+
toBlock.getId().check(CopyUtil.readBytes(toBlock.getRawInputStream()));
+ System.err.println("...es geht mit rechten Dingen zu.");
+ throw e;
+ }
+ }
+
+
+ protected Block saveDiff(VersionBlock from, BlockId fromId,
+ VersionBlock to, BlockId toId) throws IOException {
+ Header822 hdr = new SortedHeader822();
+ hdr.add("Content-Type", diffContentType);
+ hdr.add("Content-Transfer-Encoding", "binary");
+ hdr.add("X-Gzz-Diff-From", fromId.getHex());
+ hdr.add("X-Gzz-Diff-To", toId.getHex());
+
+ BlockOutputStream bos = pool.getBlockOutputStream(hdr);
+ from.header.writeTo(bos);
+ to.header.writeTo(bos);
+ format.writeDiff(bos, to.version.getDiffFrom(from.version));
+ bos.close();
+
+ return bos.getBlock();
+ }
// should be simply named .Group
Index: gzz/lava/gzz/storm/util/SimpleStormFiler.java
diff -u gzz/lava/gzz/storm/util/SimpleStormFiler.java:1.2
gzz/lava/gzz/storm/util/SimpleStormFiler.java:1.3
--- gzz/lava/gzz/storm/util/SimpleStormFiler.java:1.2 Tue Jan 14 12:20:48 2003
+++ gzz/lava/gzz/storm/util/SimpleStormFiler.java Sat Jan 18 18:56:36 2003
@@ -37,15 +37,15 @@
public Version load() throws IOException {
if(current == null) return emptyVersion;
- return load(current.getTarget());
+ VersionBlock b = load(current.getTarget());
+ if(b != null) return b.version;
+ else return emptyVersion;
}
- public Version load(BlockId id) throws IOException {
+ public VersionBlock load(BlockId id) throws IOException {
+ if(id == null) return null;
Block block = pool.get(id);
- InputStream is = block.getInputStream();
- Version v = format.readVersion(is);
- is.close();
- return v;
+ return new VersionBlock(block, format);
}
public void save(Version v) throws IOException {
Index: gzz/lava/gzz/storm/util/VersionBlock.java
diff -u gzz/lava/gzz/storm/util/VersionBlock.java:1.2
gzz/lava/gzz/storm/util/VersionBlock.java:1.3
--- gzz/lava/gzz/storm/util/VersionBlock.java:1.2 Sat Jan 18 12:37:25 2003
+++ gzz/lava/gzz/storm/util/VersionBlock.java Sat Jan 18 18:56:36 2003
@@ -16,6 +16,13 @@
this.version = version;
}
+ public VersionBlock(Block block, VersionFormat format) throws IOException {
+ super(block.getHeader(), format);
+ InputStream in = block.getInputStream();
+ this.version = format.readVersion(in);
+ in.close();
+ }
+
public void writeTo(OutputStream out) throws IOException {
header.writeTo(out);
format.writeVersion(out, version);
Index: gzz/lava/test/gzz/storm/StormPoolTest.java
diff -u gzz/lava/test/gzz/storm/StormPoolTest.java:1.14
gzz/lava/test/gzz/storm/StormPoolTest.java:1.15
--- gzz/lava/test/gzz/storm/StormPoolTest.java:1.14 Mon Jan 13 20:04:46 2003
+++ gzz/lava/test/gzz/storm/StormPoolTest.java Sat Jan 18 18:56:36 2003
@@ -49,6 +49,8 @@
throw new Error();
if(b.getPool() != pool)
throw new Error();
+
+ b.getId().check(CopyUtil.readBytes(b.getRawInputStream()));
InputStreamReader isr = new InputStreamReader(b.getInputStream());
char[] array = new char[12];
@@ -93,6 +95,7 @@
bos.close();
Block block = bos.getBlock();
+ block.getId().check(CopyUtil.readBytes(block.getRawInputStream()));
InputStream is = block.getInputStream();
for(int i=0; i<expectedBody.length; i++)
if(is.read() != expectedBody[i])
@@ -220,6 +223,11 @@
if(!id.equals(id2))
throw new Error("bos.getBlock().getId() does not match: "+id2);
+
+ Block b = bos.getBlock();
+ id.check(CopyUtil.readBytes(b.getRawInputStream()));
+ id1.check(CopyUtil.readBytes(b.getRawInputStream()));
+ id2.check(CopyUtil.readBytes(b.getRawInputStream()));
}
/** Test that trying to get a nonexistent block
Index: gzz/lava/test/gzz/storm/util/StormFilerBlock.test
diff -u gzz/lava/test/gzz/storm/util/StormFilerBlock.test:1.2
gzz/lava/test/gzz/storm/util/StormFilerBlock.test:1.3
--- gzz/lava/test/gzz/storm/util/StormFilerBlock.test:1.2 Sat Jan 18
17:09:40 2003
+++ gzz/lava/test/gzz/storm/util/StormFilerBlock.test Sat Jan 18 18:56:36 2003
@@ -82,6 +82,8 @@
else:
assert 0
+ assert block.getFromId() == block.getToId() == None
+
def testDiffBlockFromTo():
id1 = gzz.storm.BlockId(