[jboss-cvs] JBoss Messaging SVN: r5404 - in trunk: src/main/org/jboss/messaging/core/journal/impl and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Nov 20 19:46:04 EST 2008
Author: clebert.suconic at jboss.com
Date: 2008-11-20 19:46:03 -0500 (Thu, 20 Nov 2008)
New Revision: 5404
Removed:
trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/ByteArrayEncoding.java
Modified:
trunk/src/main/org/jboss/messaging/core/journal/Journal.java
trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java
trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java
trunk/tests/src/org/jboss/messaging/tests/performance/journal/JournalImplTestUnit.java
trunk/tests/src/org/jboss/messaging/tests/stress/journal/remote/RemoteJournalAppender.java
trunk/tests/src/org/jboss/messaging/tests/timing/core/journal/impl/JournalImplTestUnit.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AlignedJournalImplTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestBase.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestUnit.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/persistence/impl/journal/JournalStorageManagerTest.java
Log:
Adding old add/update methods with byte array on journal making more user friendly for other systems to use the journal
Modified: trunk/src/main/org/jboss/messaging/core/journal/Journal.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/Journal.java 2008-11-20 19:10:37 UTC (rev 5403)
+++ trunk/src/main/org/jboss/messaging/core/journal/Journal.java 2008-11-21 00:46:03 UTC (rev 5404)
@@ -38,20 +38,32 @@
{
// Non transactional operations
+ void appendAddRecord(long id, byte recordType, byte[] record) throws Exception;
+
void appendAddRecord(long id, byte recordType, EncodingSupport record) throws Exception;
+ void appendUpdateRecord(long id, byte recordType, byte[] record) throws Exception;
+
void appendUpdateRecord(long id, byte recordType, EncodingSupport record) throws Exception;
void appendDeleteRecord(long id) throws Exception;
// Transactional operations
+ void appendAddRecordTransactional(long txID, long id, byte recordType, byte[] record) throws Exception;
+
void appendAddRecordTransactional(long txID, long id, byte recordType, EncodingSupport record) throws Exception;
+ void appendUpdateRecordTransactional(long txID, long id, byte recordType, byte[] record) throws Exception;
+
void appendUpdateRecordTransactional(long txID, long id, byte recordType, EncodingSupport record) throws Exception;
+ void appendDeleteRecordTransactional(long txID, long id, byte[] record) throws Exception;
+
void appendDeleteRecordTransactional(long txID, long id, EncodingSupport record) throws Exception;
+ void appendDeleteRecordTransactional(long txID, long id) throws Exception;
+
void appendCommitRecord(long txID) throws Exception;
/**
Modified: trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java 2008-11-20 19:10:37 UTC (rev 5403)
+++ trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java 2008-11-21 00:46:03 UTC (rev 5404)
@@ -61,6 +61,7 @@
import org.jboss.messaging.core.journal.TestableJournal;
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.remoting.impl.ByteBufferWrapper;
+import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
import org.jboss.messaging.util.Pair;
import org.jboss.messaging.util.VariableLatch;
@@ -283,6 +284,11 @@
// Journal implementation
// ----------------------------------------------------------------
+ public void appendAddRecord(final long id, final byte recordType, final byte[] record) throws Exception
+ {
+ appendAddRecord(id, recordType, new ByteArrayEncoding(record));
+ }
+
public void appendAddRecord(final long id, final byte recordType, final EncodingSupport record) throws Exception
{
if (state != STATE_LOADED)
@@ -323,6 +329,11 @@
}
}
+ public void appendUpdateRecord(final long id, final byte recordType, final byte[] record) throws Exception
+ {
+ appendUpdateRecord(id, recordType, new ByteArrayEncoding(record));
+ }
+
public void appendUpdateRecord(final long id, final byte recordType, final EncodingSupport record) throws Exception
{
if (state != STATE_LOADED)
@@ -410,6 +421,12 @@
}
}
+ public void appendAddRecordTransactional(final long txID, final long id, final byte recordType, final byte[] record) throws Exception
+ {
+ appendAddRecordTransactional(txID, id, recordType, new ByteArrayEncoding(record));
+
+ }
+
public void appendAddRecordTransactional(final long txID,
final long id,
final byte recordType,
@@ -459,6 +476,14 @@
public void appendUpdateRecordTransactional(final long txID,
final long id,
final byte recordType,
+ final byte[] record) throws Exception
+ {
+ appendUpdateRecordTransactional(txID, id, recordType, new ByteArrayEncoding(record));
+ }
+
+ public void appendUpdateRecordTransactional(final long txID,
+ final long id,
+ final byte recordType,
final EncodingSupport record) throws Exception
{
if (state != STATE_LOADED)
@@ -500,6 +525,11 @@
}
}
+ public void appendDeleteRecordTransactional(final long txID, final long id, final byte[] record) throws Exception
+ {
+ appendDeleteRecordTransactional(txID, id, new ByteArrayEncoding(record));
+ }
+
public void appendDeleteRecordTransactional(final long txID, final long id, final EncodingSupport record) throws Exception
{
if (state != STATE_LOADED)
@@ -543,6 +573,45 @@
}
}
+ public void appendDeleteRecordTransactional(final long txID, final long id) throws Exception
+ {
+ if (state != STATE_LOADED)
+ {
+ throw new IllegalStateException("Journal must be loaded first");
+ }
+
+ int size = SIZE_DELETE_RECORD_TX;
+
+ ByteBufferWrapper bb = new ByteBufferWrapper(newBuffer(size));
+
+ bb.putByte(DELETE_RECORD_TX);
+ bb.putInt(-1); // skip ID part
+ bb.putLong(txID);
+ bb.putLong(id);
+ bb.putInt(0);
+ bb.putInt(size);
+
+ try
+ {
+ JournalFile usedFile = appendRecord(bb.getBuffer(), false, getTransactionCallback(txID));
+
+ JournalTransaction tx = getTransactionInfo(txID);
+
+ tx.addNegative(usedFile, id);
+ }
+ finally
+ {
+ try
+ {
+ rwlock.readLock().unlock();
+ }
+ catch (Exception ignored)
+ {
+ // This could happen if the thread was interrupted
+ }
+ }
+ }
+
/**
*
* <p>If the system crashed after a prepare was called, it should store information that is required to bring the transaction
@@ -2552,5 +2621,51 @@
}
}
+
+
+ private class ByteArrayEncoding implements EncodingSupport
+ {
+ // Constants -----------------------------------------------------
+ final byte[] data;
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ public ByteArrayEncoding(final byte[] data)
+ {
+ this.data = data;
+ }
+
+ // Public --------------------------------------------------------
+
+ public void decode(final MessagingBuffer buffer)
+ {
+ throw new IllegalStateException("operation not supported");
+ }
+
+ public void encode(final MessagingBuffer buffer)
+ {
+ buffer.putBytes(data);
+ }
+
+ public int getEncodeSize()
+ {
+ return data.length;
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+ }
+
+
}
Modified: trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java 2008-11-20 19:10:37 UTC (rev 5403)
+++ trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java 2008-11-21 00:46:03 UTC (rev 5404)
@@ -300,7 +300,7 @@
{
// Instead of updating the record, we delete the old one as that is
// better for reclaiming
- messageJournal.appendDeleteRecordTransactional(txID, pageTransaction.getRecordID(), null);
+ messageJournal.appendDeleteRecordTransactional(txID, pageTransaction.getRecordID());
}
pageTransaction.setRecordID(generateUniqueID());
@@ -317,7 +317,7 @@
{
// To avoid linked list effect on reclaiming, we delete and add a new
// record, instead of simply updating it
- messageJournal.appendDeleteRecordTransactional(txID, lastPage.getRecordId(), null);
+ messageJournal.appendDeleteRecordTransactional(txID, lastPage.getRecordId());
}
lastPage.setRecordId(generateUniqueID());
@@ -332,7 +332,7 @@
public void storeDeletePageTransaction(final long txID, final long recordID) throws Exception
{
- messageJournal.appendDeleteRecordTransactional(txID, recordID, null);
+ messageJournal.appendDeleteRecordTransactional(txID, recordID);
}
public void updateScheduledDeliveryTimeTransactional(final long txID, final MessageReference ref) throws Exception
Modified: trunk/tests/src/org/jboss/messaging/tests/performance/journal/JournalImplTestUnit.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/performance/journal/JournalImplTestUnit.java 2008-11-20 19:10:37 UTC (rev 5403)
+++ trunk/tests/src/org/jboss/messaging/tests/performance/journal/JournalImplTestUnit.java 2008-11-21 00:46:03 UTC (rev 5404)
@@ -31,7 +31,6 @@
import org.jboss.messaging.core.journal.impl.JournalImpl;
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.tests.unit.core.journal.impl.JournalImplTestBase;
-import org.jboss.messaging.tests.unit.core.journal.impl.fakes.ByteArrayEncoding;
import org.jboss.messaging.tests.unit.core.journal.impl.fakes.SimpleEncoding;
/**
@@ -157,7 +156,7 @@
for (int count = 0; count < NUMBER_OF_RECORDS; count++)
{
- journal.appendAddRecord(count, (byte)0, new ByteArrayEncoding(record));
+ journal.appendAddRecord(count, (byte)0, record);
if (count >= NUMBER_OF_RECORDS / 2)
{
Modified: trunk/tests/src/org/jboss/messaging/tests/stress/journal/remote/RemoteJournalAppender.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/stress/journal/remote/RemoteJournalAppender.java 2008-11-20 19:10:37 UTC (rev 5403)
+++ trunk/tests/src/org/jboss/messaging/tests/stress/journal/remote/RemoteJournalAppender.java 2008-11-21 00:46:03 UTC (rev 5404)
@@ -32,7 +32,6 @@
import org.jboss.messaging.core.journal.impl.AIOSequentialFileFactory;
import org.jboss.messaging.core.journal.impl.JournalImpl;
import org.jboss.messaging.core.journal.impl.NIOSequentialFileFactory;
-import org.jboss.messaging.tests.unit.core.journal.impl.fakes.ByteArrayEncoding;
/**
*
@@ -212,7 +211,7 @@
if (transactionSize != 0)
{
- journal.appendAddRecordTransactional(transactionId, id, (byte)99, new ByteArrayEncoding(buffer.array()));
+ journal.appendAddRecordTransactional(transactionId, id, (byte)99, buffer.array());
if (++transactionCounter == transactionSize)
{
@@ -224,7 +223,7 @@
}
else
{
- journal.appendAddRecord(id, (byte)99, new ByteArrayEncoding(buffer.array()));
+ journal.appendAddRecord(id, (byte)99, buffer.array());
}
}
Modified: trunk/tests/src/org/jboss/messaging/tests/timing/core/journal/impl/JournalImplTestUnit.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/timing/core/journal/impl/JournalImplTestUnit.java 2008-11-20 19:10:37 UTC (rev 5403)
+++ trunk/tests/src/org/jboss/messaging/tests/timing/core/journal/impl/JournalImplTestUnit.java 2008-11-21 00:46:03 UTC (rev 5404)
@@ -29,7 +29,6 @@
import org.jboss.messaging.core.journal.RecordInfo;
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.tests.unit.core.journal.impl.JournalImplTestBase;
-import org.jboss.messaging.tests.unit.core.journal.impl.fakes.ByteArrayEncoding;
/**
*
@@ -153,7 +152,7 @@
for (int count = 0; count < NUMBER_OF_RECORDS; count++)
{
- journal.appendAddRecord(count, (byte)0, new ByteArrayEncoding(record));
+ journal.appendAddRecord(count, (byte)0, record);
if (count >= NUMBER_OF_RECORDS / 2)
{
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AlignedJournalImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AlignedJournalImplTest.java 2008-11-20 19:10:37 UTC (rev 5403)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AlignedJournalImplTest.java 2008-11-21 00:46:03 UTC (rev 5404)
@@ -38,7 +38,6 @@
import org.jboss.messaging.core.journal.SequentialFileFactory;
import org.jboss.messaging.core.journal.impl.JournalImpl;
import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.tests.unit.core.journal.impl.fakes.ByteArrayEncoding;
import org.jboss.messaging.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory;
import org.jboss.messaging.tests.unit.core.journal.impl.fakes.SimpleEncoding;
import org.jboss.messaging.tests.util.UnitTestCase;
@@ -209,7 +208,7 @@
{
bytes[j] = (byte)i;
}
- journalImpl.appendAddRecord(i * 100l, (byte)i, new ByteArrayEncoding(bytes));
+ journalImpl.appendAddRecord(i * 100l, (byte)i, bytes);
}
for (int i = 25; i < 50; i++)
@@ -244,7 +243,7 @@
bytes[j] = (byte)'x';
}
- journalImpl.appendUpdateRecord(i * 100l, (byte)i, new ByteArrayEncoding(bytes));
+ journalImpl.appendUpdateRecord(i * 100l, (byte)i, bytes);
}
setupJournal(JOURNAL_SIZE, 1024);
@@ -512,7 +511,7 @@
for (int i = 0; i < 10; i++)
{
- journalImpl.appendDeleteRecordTransactional(2l, i, null);
+ journalImpl.appendDeleteRecordTransactional(2l, i);
journalImpl.forceMoveNextFile();
}
@@ -818,7 +817,7 @@
for (int i = 0; i < 10; i++)
{
- journalImpl.appendDeleteRecordTransactional(2l, i, null);
+ journalImpl.appendDeleteRecordTransactional(2l, i);
}
journalImpl.appendCommitRecord(2l);
@@ -863,7 +862,7 @@
{
journalImpl.forceMoveNextFile();
}
- journalImpl.appendDeleteRecordTransactional(2l, i, null);
+ journalImpl.appendDeleteRecordTransactional(2l, i);
}
journalImpl.appendCommitRecord(2l);
@@ -979,7 +978,7 @@
for (int i = 0; i < 10; i++)
{
- journalImpl.appendDeleteRecordTransactional(2l, i, null);
+ journalImpl.appendDeleteRecordTransactional(2l, i);
}
SimpleEncoding xid2 = new SimpleEncoding(15, (byte)2);
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestBase.java 2008-11-20 19:10:37 UTC (rev 5403)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestBase.java 2008-11-21 00:46:03 UTC (rev 5404)
@@ -38,7 +38,6 @@
import org.jboss.messaging.core.journal.TestableJournal;
import org.jboss.messaging.core.journal.impl.JournalImpl;
import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.tests.unit.core.journal.impl.fakes.ByteArrayEncoding;
import org.jboss.messaging.tests.util.RandomUtil;
import org.jboss.messaging.tests.util.UnitTestCase;
@@ -217,7 +216,7 @@
{
byte[] record = generateRecord(size);
- journal.appendAddRecord(element, (byte)0, new ByteArrayEncoding(record));
+ journal.appendAddRecord(element, (byte)0, record);
records.add(new RecordInfo(element, (byte)0, record, false));
}
@@ -231,7 +230,7 @@
{
byte[] updateRecord = generateRecord(recordLength);
- journal.appendUpdateRecord(element, (byte)0, new ByteArrayEncoding(updateRecord));
+ journal.appendUpdateRecord(element, (byte)0, updateRecord);
records.add(new RecordInfo(element, (byte)0, updateRecord, true));
}
@@ -261,7 +260,7 @@
// SIZE_BYTE
byte[] record = generateRecord(recordLength - JournalImpl.SIZE_ADD_RECORD_TX);
- journal.appendAddRecordTransactional(txID, element, (byte)0, new ByteArrayEncoding(record));
+ journal.appendAddRecordTransactional(txID, element, (byte)0, record);
tx.records.add(new RecordInfo(element, (byte)0, record, false));
@@ -278,7 +277,7 @@
{
byte[] updateRecord = generateRecord(recordLength - JournalImpl.SIZE_UPDATE_RECORD_TX);
- journal.appendUpdateRecordTransactional(txID, element, (byte)0, new ByteArrayEncoding(updateRecord));
+ journal.appendUpdateRecordTransactional(txID, element, (byte)0, updateRecord);
tx.records.add(new RecordInfo(element, (byte)0, updateRecord, true));
}
@@ -291,7 +290,7 @@
for (long element : arguments)
{
- journal.appendDeleteRecordTransactional(txID, element, null);
+ journal.appendDeleteRecordTransactional(txID, element);
tx.deletes.add(new RecordInfo(element, (byte)0, null, true));
}
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestUnit.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestUnit.java 2008-11-20 19:10:37 UTC (rev 5403)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/JournalImplTestUnit.java 2008-11-21 00:46:03 UTC (rev 5404)
@@ -28,7 +28,6 @@
import org.jboss.messaging.core.journal.RecordInfo;
import org.jboss.messaging.core.journal.impl.JournalImpl;
import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.tests.unit.core.journal.impl.fakes.ByteArrayEncoding;
import org.jboss.messaging.tests.unit.core.journal.impl.fakes.SimpleEncoding;
/**
@@ -2259,7 +2258,7 @@
{
byte[] record = generateRecord(10 + (int)(1500 * Math.random()));
- journal.appendAddRecord(i, (byte)0, new ByteArrayEncoding(record));
+ journal.appendAddRecord(i, (byte)0, record);
records.add(new RecordInfo(i, (byte)0, record, false));
}
@@ -2268,7 +2267,7 @@
{
byte[] record = generateRecord(10 + (int)(1024 * Math.random()));
- journal.appendUpdateRecord(i, (byte)0, new ByteArrayEncoding(record));
+ journal.appendUpdateRecord(i, (byte)0, record);
records.add(new RecordInfo(i, (byte)0, record, true));
}
Deleted: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/ByteArrayEncoding.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/ByteArrayEncoding.java 2008-11-20 19:10:37 UTC (rev 5403)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/ByteArrayEncoding.java 2008-11-21 00:46:03 UTC (rev 5404)
@@ -1,75 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.tests.unit.core.journal.impl.fakes;
-
-import org.jboss.messaging.core.journal.EncodingSupport;
-import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
-
-/**
- *
- * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
- *
- */
-public class ByteArrayEncoding implements EncodingSupport
-{
-
- // Constants -----------------------------------------------------
- final byte[] data;
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public ByteArrayEncoding(final byte[] data)
- {
- this.data = data;
- }
-
- // Public --------------------------------------------------------
-
- public void decode(final MessagingBuffer buffer)
- {
- throw new IllegalStateException("operation not supported");
- }
-
- public void encode(final MessagingBuffer buffer)
- {
- buffer.putBytes(data);
- }
-
- public int getEncodeSize()
- {
- return data.length;
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
-}
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/persistence/impl/journal/JournalStorageManagerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/persistence/impl/journal/JournalStorageManagerTest.java 2008-11-20 19:10:37 UTC (rev 5403)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/persistence/impl/journal/JournalStorageManagerTest.java 2008-11-21 00:46:03 UTC (rev 5404)
@@ -168,7 +168,7 @@
final long messageID = 101921092;
final long txID = 1209373;
- messageJournal.appendDeleteRecordTransactional(txID, messageID, null);
+ messageJournal.appendDeleteRecordTransactional(txID, messageID);
EasyMock.replay(messageJournal, bindingsJournal);
jsm.storeDeletePageTransaction(txID, messageID);
EasyMock.verify(messageJournal, bindingsJournal);
More information about the jboss-cvs-commits
mailing list