teiid SVN: r3508 - in trunk: documentation/admin-guide/src/main/docbook/en-US/content and 6 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-09-29 22:00:28 -0400 (Thu, 29 Sep 2011)
New Revision: 3508
Removed:
trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockBitSetTree.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockClosedLongIntHashTable.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockManager.java
trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockBitSetTree.java
trunk/engine/src/test/java/org/teiid/common/buffer/impl/…
[View More]TestBlockClosedLongIntHashTable.java
trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStoreCache.java
Modified:
trunk/common-core/src/test/java/org/teiid/core/util/UnitTestUtil.java
trunk/documentation/admin-guide/src/main/docbook/en-US/content/installation.xml
trunk/engine/src/main/java/org/teiid/common/buffer/Cache.java
trunk/engine/src/main/java/org/teiid/common/buffer/FileStore.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/ExtensibleBufferedOutputStream.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStoreCache.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/MemoryStorageManager.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java
trunk/engine/src/test/java/org/teiid/common/buffer/BufferManagerFactory.java
trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
trunk/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java
Log:
TEIID-1750 converting storage back over to the old file algorithm (1 filestore per table/tuplebuffer) with an updated compaction algorithm
Modified: trunk/common-core/src/test/java/org/teiid/core/util/UnitTestUtil.java
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/util/UnitTestUtil.java 2011-09-29 16:46:38 UTC (rev 3507)
+++ trunk/common-core/src/test/java/org/teiid/core/util/UnitTestUtil.java 2011-09-30 02:00:28 UTC (rev 3508)
@@ -50,6 +50,45 @@
*/
public class UnitTestUtil {
+ public static final class LogFormatter extends Formatter {
+ @Override
+ public String format(LogRecord record) {
+ final StringBuilder result = new StringBuilder();
+ result.append(new Timestamp(record.getMillis()));
+ result.append(" "); //$NON-NLS-1$
+ result.append(record.getLoggerName());
+ result.append(" "); //$NON-NLS-1$
+ result.append(record.getLevel());
+ result.append(" "); //$NON-NLS-1$
+ result.append(Thread.currentThread().getName());
+ result.append(" "); //$NON-NLS-1$
+ result.append(record.getMessage());
+ result.append('\n');
+ if (record.getThrown() != null) {
+ record.getThrown().printStackTrace(new PrintWriter(new Writer() {
+
+ @Override
+ public void close() throws IOException {
+
+ }
+
+ @Override
+ public void flush() throws IOException {
+
+ }
+
+ @Override
+ public void write(char[] cbuf, int off, int len)
+ throws IOException {
+ result.append(new String(cbuf, off, len));
+ }
+ }));
+ result.append('\n');
+ }
+ return result.toString();
+ }
+ }
+
public static final String PATH_SEPARATOR = "/"; //$NON-NLS-1$
private static final String DEFAULT_TESTDATA_PATH = "src/test/resources"; //$NON-NLS-1$
@@ -419,45 +458,7 @@
} else {
logger.setUseParentHandlers(false);
ConsoleHandler ch = new ConsoleHandler();
- ch.setFormatter(new Formatter() {
-
- @Override
- public String format(LogRecord record) {
- final StringBuilder result = new StringBuilder();
- result.append(new Timestamp(record.getMillis()));
- result.append(" "); //$NON-NLS-1$
- result.append(record.getLoggerName());
- result.append(" "); //$NON-NLS-1$
- result.append(record.getLevel());
- result.append(" "); //$NON-NLS-1$
- result.append(record.getThreadID());
- result.append(" "); //$NON-NLS-1$
- result.append(record.getMessage());
- result.append('\n');
- if (record.getThrown() != null) {
- record.getThrown().printStackTrace(new PrintWriter(new Writer() {
-
- @Override
- public void close() throws IOException {
-
- }
-
- @Override
- public void flush() throws IOException {
-
- }
-
- @Override
- public void write(char[] cbuf, int off, int len)
- throws IOException {
- result.append(new String(cbuf, off, len));
- }
- }));
- result.append('\n');
- }
- return result.toString();
- }
- });
+ ch.setFormatter(new LogFormatter());
ch.setLevel(Level.FINEST);
logger.addHandler(ch);
}
Modified: trunk/documentation/admin-guide/src/main/docbook/en-US/content/installation.xml
===================================================================
--- trunk/documentation/admin-guide/src/main/docbook/en-US/content/installation.xml 2011-09-29 16:46:38 UTC (rev 3507)
+++ trunk/documentation/admin-guide/src/main/docbook/en-US/content/installation.xml 2011-09-30 02:00:28 UTC (rev 3508)
@@ -98,7 +98,8 @@
/deployers
/teiid.deployer
/lib
- /teiid-examples]]></programlisting>
+ /teiid-examples
+ /tmp/teiid]]></programlisting>
</example>
<section>
<title>/deploy/teiid/teiid-jboss-beans.xml</title>
@@ -163,6 +164,14 @@
<title>teiid-docs</title>
<para>This directory contains the PDF documents related Teiid and Teiid development. </para>
</section>
+
+ <section>
+ <title>tmp/teiid</title>
+ <para>This directory contains temporary files created by Teiid. These are mostly created by the buffer manager.
+ These files are not needed across a VM restart. Heavy usage of large data sets will create lots of temporary files.
+ In heavy usage scenarios, consider pointing the buffer directory at a partition that is routinely defragmented.
+ </para>
+ </section>
</section>
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/Cache.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/Cache.java 2011-09-29 16:46:38 UTC (rev 3507)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/Cache.java 2011-09-30 02:00:28 UTC (rev 3508)
@@ -31,9 +31,11 @@
*/
public interface Cache extends StorageManager {
void createCacheGroup(Long gid); //called prior to adding an entry
+ //TODO: this should use a callback on the buffermangaer to remove memory entries
+ //without materializing all group keys
Collection<Long> removeCacheGroup(Long gid);
void addToCacheGroup(Long gid, Long oid);
CacheEntry get(Long id, Serializer<?> serializer) throws TeiidComponentException;
- void add(CacheEntry entry, Serializer<?> s);
+ void add(CacheEntry entry, Serializer<?> s) throws Exception;
void remove(Long gid, Long id);
}
\ No newline at end of file
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/FileStore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/FileStore.java 2011-09-29 16:46:38 UTC (rev 3507)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/FileStore.java 2011-09-30 02:00:28 UTC (rev 3508)
@@ -25,7 +25,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -224,28 +223,6 @@
};
}
- public ByteBuffer getBuffer(long start, int length, boolean allocate) throws IOException {
- byte[] b = new byte[length];
- if (!allocate) {
- readFully(start, b, 0, length);
- }
- return ByteBuffer.wrap(b);
- }
-
- public void updateFromBuffer(ByteBuffer bb, long start) throws IOException {
- byte[] b = null;
- int offset = 0;
- bb.rewind();
- if (bb.hasArray()) {
- b = bb.array();
- offset = bb.arrayOffset();
- } else {
- b = new byte[bb.limit()];
- bb.get(b);
- }
- write(start, b, offset, bb.limit());
- }
-
public InputStream createInputStream(final long start) {
return createInputStream(start, -1);
}
Deleted: trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockBitSetTree.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockBitSetTree.java 2011-09-29 16:46:38 UTC (rev 3507)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockBitSetTree.java 2011-09-30 02:00:28 UTC (rev 3508)
@@ -1,191 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library 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 library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
- package org.teiid.common.buffer.impl;
-
-import java.util.BitSet;
-
-import org.teiid.common.buffer.impl.FileStoreCache.BlockInfo;
-
-/**
- * Extends a {@link BitSet} by adding a cumulative total and a
- * first level index to speed queries against large bitsets.
- */
-public class BlockBitSetTree {
-
- private static final int LOG_BITS_PER_BLOCK = FileStoreCache.LOG_BLOCK_SIZE + 3;
- private static final int MAX_TOP_VALUE = 1 << LOG_BITS_PER_BLOCK;
- private int maxIndex;
- private int bitsSet;
- private int[] topVals;
- private BlockManager blockManager;
- private int blockCount = 0;
-
- public BlockBitSetTree(int maxIndex, BlockManager blockManager) {
- this.maxIndex = maxIndex;
- this.blockManager = blockManager;
- this.topVals = new int[(maxIndex >> (FileStoreCache.LOG_BLOCK_SIZE + 3)) + 1];
- }
-
- public int getMaxIndex() {
- return maxIndex;
- }
-
- /**
- * Set the given bit at the index.
- * @param bitIndex
- * @param value
- */
- public synchronized void set(int bitIndex, boolean value) {
- getOrSet(bitIndex, value, true);
- }
-
- public synchronized boolean get(int bitIndex) {
- return getOrSet(bitIndex, false, false);
- }
-
- private boolean getOrSet(int bitIndex, boolean value, boolean update) {
- if (bitIndex > maxIndex) {
- throw new ArrayIndexOutOfBoundsException(bitIndex);
- }
- int blockIndex = bitIndex>>LOG_BITS_PER_BLOCK;
- BlockInfo bb = null;
- if (blockIndex >= blockCount) {
- if (!update) {
- return false;
- }
- for (; blockCount < blockIndex+1; blockCount++) {
- bb = blockManager.allocateBlock(blockCount);
- bb.buf.position(0);
- int longsPerBlock = FileStoreCache.BLOCK_SIZE >> 6;
- for (int j = 0; j < longsPerBlock; j++) {
- bb.buf.putLong(0);
- }
- }
- } else {
- bb = blockManager.getBlock(blockIndex);
- }
- int relativeIndex = bitIndex&(MAX_TOP_VALUE-1);
- int longByteIndex = (relativeIndex>>6)<<3;
- long word = bb.buf.getLong(longByteIndex);
- long mask = 1L << bitIndex;
- boolean currentValue = ((word & mask) != 0);
- if (!update) {
- return currentValue;
- }
- if (currentValue == value) {
- return currentValue;
- }
- if (value) {
- word |= mask;
- } else {
- word &= ~mask;
- }
- bb.buf.putLong(longByteIndex, word);
- blockManager.updateBlock(bb);
- int topIndex = bitIndex >> LOG_BITS_PER_BLOCK;
- int increment = value?1:-1;
- bitsSet+=increment;
- topVals[topIndex]+=increment;
- return currentValue;
- }
-
- public synchronized int getBitsSet() {
- return bitsSet;
- }
-
- public synchronized int nextClearBit(int fromIndex) {
- int start = fromIndex >> LOG_BITS_PER_BLOCK;
- for (int i = start; i < topVals.length; i++) {
- if (topVals[i] == MAX_TOP_VALUE) {
- continue;
- }
- if (topVals[i] == 0) {
- if (i == start) {
- return fromIndex;
- }
- return i * MAX_TOP_VALUE;
- }
- int relativeIndex = 0;
- if (i == start) {
- relativeIndex = fromIndex&(MAX_TOP_VALUE-1);
- }
- BlockInfo bb = blockManager.getBlock(i);
-
- int longByteIndex = (relativeIndex>>6)<<3;
-
- long word = ~bb.buf.getLong(longByteIndex) & (-1l << relativeIndex);
-
- while (true) {
- if (word != 0) {
- return longByteIndex*8 + (i * MAX_TOP_VALUE) + Long.numberOfTrailingZeros(word);
- }
- longByteIndex+=8;
- if (longByteIndex > FileStoreCache.BLOCK_MASK) {
- break;
- }
- word = ~bb.buf.getLong(longByteIndex);
- }
- }
- return -1;
- }
-
- public synchronized int nextSetBit(int fromIndex) {
- if (bitsSet == 0) {
- return -1;
- }
- int start = fromIndex >> LOG_BITS_PER_BLOCK;
- for (int i = start; i < topVals.length; i++) {
- if (topVals[i] == 0) {
- continue;
- }
- if (topVals[i] == MAX_TOP_VALUE) {
- if (i == start) {
- return fromIndex;
- }
- return i * MAX_TOP_VALUE;
- }
- int relativeIndex = 0;
- if (i == start) {
- relativeIndex = fromIndex&(MAX_TOP_VALUE-1);
- }
- BlockInfo bb = blockManager.getBlock(i);
-
- int longByteIndex = (relativeIndex>>6)<<3;
-
- long word = bb.buf.getLong(longByteIndex) & (-1l << relativeIndex);
-
- while (true) {
- if (word != 0) {
- return longByteIndex*8 + (i * MAX_TOP_VALUE) + Long.numberOfTrailingZeros(word);
- }
- longByteIndex+=8;
- if (longByteIndex > FileStoreCache.BLOCK_MASK) {
- break;
- }
- word = bb.buf.getLong(longByteIndex);
- }
- }
- return -1;
- }
-
-}
Deleted: trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockClosedLongIntHashTable.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockClosedLongIntHashTable.java 2011-09-29 16:46:38 UTC (rev 3507)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockClosedLongIntHashTable.java 2011-09-30 02:00:28 UTC (rev 3508)
@@ -1,238 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library 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 library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.common.buffer.impl;
-
-import java.nio.ByteBuffer;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.teiid.common.buffer.impl.FileStoreCache.BlockInfo;
-
-/**
- * Represents the logical structure of a cache group / directory
- *
- * Implemented by a closed hash table using a single step linear probe with delayed removal.
- * Uses power of 2 hashing.
- *
- * Provides an extremely simple hash structure that rivals {@link HashMap} performance and
- * is directly mapped to {@link ByteBuffer}s to avoid serialization overhead.
- *
- * Does not expect keys or values to be negative.
- */
-public class BlockClosedLongIntHashTable {
-
- private enum Mode {
- GET,
- UPDATE,
- REMOVE
- }
-
- private static final int BYTES_PER_ROW = 12; //8+4
- private static final int BLOCK_SIZE = FileStoreCache.BLOCK_DATA_BYTES/BYTES_PER_ROW;
- private static final float LOAD_FACTOR = .7f;
- private static final int MIN_SIZE = 1 << (31 - Integer.numberOfLeadingZeros(BLOCK_SIZE)); //should fit in a single block
-
- static final int EMPTY = -1;
- private static final int REMOVED = -2;
-
- protected int size;
- protected int capacityMask = EMPTY;
- protected BlockManager blockManager;
-
- public BlockClosedLongIntHashTable(BlockManager blockManager) {
- this.blockManager = blockManager;
- }
-
- private void init(int capacity) {
- int currentBlockCount = blockCount(capacityMask + 1);
- int desiredBlockCount = blockCount(capacity);
- if (capacity > capacityMask) {
- for (int i = currentBlockCount; i < desiredBlockCount; i++) {
- BlockInfo bb = blockManager.allocateBlock(i);
- empty(bb.buf, BLOCK_SIZE);
- blockManager.updateBlock(bb);
- }
- }
- capacityMask = capacity - 1;
- }
-
- private void empty(ByteBuffer bb, int toIndex) {
- bb.position(0);
- for (int j = 0; j < toIndex; j++) {
- bb.putLong(j * BYTES_PER_ROW, EMPTY);
- }
- }
-
- private static int blockCount(int size) {
- int currentBlockCount = (size) / BLOCK_SIZE;
- if (size%BLOCK_SIZE > 0) {
- currentBlockCount++;
- }
- return currentBlockCount;
- }
-
- public synchronized int put(long key, int value) {
- int result = getOrUpdate(key, value, Mode.UPDATE);
- if ((result == EMPTY || result == REMOVED) && ++size > LOAD_FACTOR*capacityMask) {
- int newCapacity = (capacityMask+1)<<1;
- int oldLength = capacityMask + 1;
- init(newCapacity);
- rehash(oldLength, newCapacity);
- }
- return result;
- }
-
- public synchronized int get(long key) {
- return getOrUpdate(key, EMPTY, Mode.GET);
- }
-
- public synchronized int remove(long key) {
- int result = getOrUpdate(key, EMPTY, Mode.REMOVE);
- if (result != EMPTY && --size*LOAD_FACTOR < capacityMask>>3 && (capacityMask+1)>>1 >= MIN_SIZE) {
- //reduce the size of the table by half
- int oldLength = capacityMask + 1;
- capacityMask >>= 1;
- rehash(oldLength, oldLength>>1);
- int oldBlocks = blockCount(oldLength);
- int newBlocks = blockCount(capacityMask +1);
- for (int i = oldBlocks-1; i >= newBlocks; i--) {
- blockManager.freeBlock(i);
- }
- }
- return result;
- }
-
- private void rehash(int oldLength, int newLength) {
- BlockInfo lastBlockInfo = null;
- ByteBuffer lastBlock = null;
- for (int i = 0; i < oldLength; i++) {
- int relativeIndex = i%BLOCK_SIZE;
- if (lastBlock == null || relativeIndex == 0) {
- int lastIndex = i/BLOCK_SIZE;
- lastBlockInfo = blockManager.getBlock(lastIndex);
- lastBlock = lastBlockInfo.buf;
- if (i < newLength) {
- byte[] buf = new byte[FileStoreCache.BLOCK_DATA_BYTES];
- lastBlock.position(0);
- lastBlock.get(buf);
- ByteBuffer copyBlock = ByteBuffer.wrap(buf);
- empty(lastBlock, Math.min(BLOCK_SIZE, oldLength - lastIndex*BLOCK_SIZE));
- blockManager.updateBlock(lastBlockInfo);
- lastBlock = copyBlock;
- }
- }
- lastBlock.position(relativeIndex*BYTES_PER_ROW);
- long oldKey = lastBlock.getLong();
- int oldValue = lastBlock.getInt();
- if (oldKey != REMOVED && oldKey != EMPTY) {
- getOrUpdate(oldKey, oldValue, Mode.UPDATE);
- }
- }
- }
-
- @SuppressWarnings("null")
- protected int getOrUpdate(long key, int value, Mode mode) {
- if (capacityMask == EMPTY) {
- if (mode == Mode.GET || mode == Mode.REMOVE) {
- return EMPTY;
- }
- init(MIN_SIZE);
- }
- int i = hashIndex(key);
- BlockInfo lastBlockInfo = null;
- long old = EMPTY;
- int position = 0;
- while (true) {
- int relativeIndex = i%BLOCK_SIZE;
- if (lastBlockInfo == null || relativeIndex == 0) {
- int index = i/BLOCK_SIZE;
- lastBlockInfo = blockManager.getBlock(index);
- }
- position = relativeIndex*BYTES_PER_ROW;
- old = lastBlockInfo.buf.getLong(position);
- if (old == EMPTY || old == key || (mode == Mode.UPDATE && old == REMOVED)) {
- break;
- }
- i = (i + 1) & capacityMask;
- }
- int result = EMPTY;
- if (old != EMPTY && old != REMOVED) {
- result = lastBlockInfo.buf.getInt(position + 8);
- }
- switch (mode) {
- case GET:
- return result;
- case UPDATE:
- lastBlockInfo.buf.putLong(position, key);
- lastBlockInfo.buf.putInt(position + 8, value);
- blockManager.updateBlock(lastBlockInfo);
- return result;
- case REMOVE:
- if (old == EMPTY || old == REMOVED) {
- return EMPTY;
- }
- lastBlockInfo.buf.putLong(position, REMOVED);
- blockManager.updateBlock(lastBlockInfo);
- return result;
- default:
- throw new AssertionError();
- }
- }
-
- private int hashIndex(long key) {
- //start with the usual long hash
- int primaryHash = (int)(key ^ (key >>> 32));
- //allow the lower bits to spread the entries
- primaryHash += primaryHash <<= 2;
- primaryHash += primaryHash <<= 3;
- return primaryHash & capacityMask;
- }
-
- public synchronized int size() {
- return size;
- }
-
- public synchronized Map<Long, Integer> remove() {
- Map<Long, Integer> result = new HashMap<Long, Integer>();
- BlockInfo lastBlockInfo = null;
- int blockIndex = 0;
- for (int i = capacityMask; i >= 0; i--) {
- int relativeIndex = i%BLOCK_SIZE;
- if (lastBlockInfo == null || relativeIndex == BLOCK_SIZE - 1) {
- if (lastBlockInfo != null) {
- blockManager.freeBlock(blockIndex);
- }
- blockIndex = i/BLOCK_SIZE;
- lastBlockInfo = blockManager.getBlock(blockIndex);
- }
- lastBlockInfo.buf.position(relativeIndex*BYTES_PER_ROW);
- long key = lastBlockInfo.buf.getLong();
- if (key != EMPTY && key != REMOVED) {
- result.put(key, lastBlockInfo.buf.getInt());
- }
- }
- blockManager.free();
- return result;
- }
-
-}
Deleted: trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockManager.java 2011-09-29 16:46:38 UTC (rev 3507)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockManager.java 2011-09-30 02:00:28 UTC (rev 3508)
@@ -1,51 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library 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 library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.common.buffer.impl;
-
-import org.teiid.common.buffer.impl.FileStoreCache.BlockInfo;
-
-/**
- * Represents an INode
- *
- * Returned BlockInfo may be shared. If shared there and no guarantees about position and mark.
- * in particular system/index blocks can be used by multiple threads relative methods should be
- * avoided, but may be used for exclusive write operations.
- * Otherwise the position will be 0.
- *
- * Due to buffermanager locking, non-index data blocks can be assumed to be thread-safe.
- */
-public interface BlockManager {
-
- int getInode();
-
- BlockInfo allocateBlock(int index);
-
- BlockInfo getBlock(int index);
-
- void updateBlock(BlockInfo block);
-
- void freeBlock(int index);
-
- void free();
-
-}
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java 2011-09-29 16:46:38 UTC (rev 3507)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java 2011-09-30 02:00:28 UTC (rev 3508)
@@ -199,6 +199,7 @@
cache.remove(this.id, batch);
}
ce.setSerializer(this.ref);
+ ce.setPersistent(true);
if (retain) {
addMemoryEntry(ce);
}
@@ -556,7 +557,11 @@
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, ce.getId(), "writing batch to storage, total writes: ", count); //$NON-NLS-1$
}
- cache.add(ce, s);
+ try {
+ cache.add(ce, s);
+ } catch (Throwable e) {
+ LogManager.logError(LogConstants.CTX_BUFFER_MGR, e, "Error persisting batch, attempts to read batch "+ ce.getId() +" later will result in an exception"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
ce.setPersistent(true);
}
if (s.useSoftCache()) {
@@ -668,6 +673,7 @@
cleanSoftReferences();
Collection<Long> vals = cache.removeCacheGroup(id);
for (Long val : vals) {
+ //TODO: we will unnecessarily call remove on the cache, but that should be low cost
fastGet(val, prefersMemory, false);
}
}
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/ExtensibleBufferedOutputStream.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/ExtensibleBufferedOutputStream.java 2011-09-29 16:46:38 UTC (rev 3507)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/ExtensibleBufferedOutputStream.java 2011-09-30 02:00:28 UTC (rev 3508)
@@ -29,6 +29,7 @@
public abstract class ExtensibleBufferedOutputStream extends OutputStream {
protected ByteBuffer buf;
+ protected int bytesWritten;
public ExtensibleBufferedOutputStream() {
}
@@ -63,18 +64,22 @@
public void flush() throws IOException {
if (buf != null && buf.position() > 0) {
- flushDirect();
+ bytesWritten += flushDirect();
}
buf = null;
}
protected abstract ByteBuffer newBuffer();
- protected abstract void flushDirect() throws IOException;
+ protected abstract int flushDirect() throws IOException;
@Override
public void close() throws IOException {
flush();
}
+ public int getBytesWritten() {
+ return bytesWritten;
+ }
+
}
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStoreCache.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStoreCache.java 2011-09-29 16:46:38 UTC (rev 3507)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStoreCache.java 2011-09-30 02:00:28 UTC (rev 3508)
@@ -22,17 +22,23 @@
package org.teiid.common.buffer.impl;
+import java.io.BufferedInputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.nio.ByteBuffer;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.LinkedHashMap;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
+import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.locks.ReentrantLock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.teiid.common.buffer.Cache;
import org.teiid.common.buffer.CacheEntry;
@@ -40,688 +46,292 @@
import org.teiid.common.buffer.Serializer;
import org.teiid.common.buffer.StorageManager;
import org.teiid.core.TeiidComponentException;
-import org.teiid.core.TeiidRuntimeException;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.logging.MessageLevel;
import org.teiid.query.QueryPlugin;
/**
- * Implements storage against a {@link FileStore} abstraction using a filesystem paradigm.
- * The filesystem uses a 31bit address space on top of 2^14 byte blocks.
+ * A minimally blocking Cache using {@link FileStore}s.
*
- * Therefore there is 2^31*2^14 = 2^45 or 32 terabytes max of addressable space.
+ * Storage files with significant unused space are compacted after reaching a size threshold.
+ * Compacting the empty space may be costly as it is currently implemented by blocking all
+ * read/write operations against the group.
*
- * Some amount of the space is taken up by system information (inodes and use flags).
- * This is held in a separate file.
+ * Since empty is concentrated at the beginning of the store a better approach could
+ * be to users smaller file segments and move batches off of the beginning.
*
- * The 64 byte inode format is:
- * 14 32 bit direct block pointers
- * 1 32 bit block indirect pointer
- * 1 32 bit block doubly indirect pointer
- *
- * The data block format is:
- * data bytes | long gid | long oid | three byte int block num
- *
- * The gid/oid are stored with the block so that defrag/compaction can be performed
- * with minimal blocking/lookups.
- *
- * This means that the maximum number of blocks available to a "file" is
- * 14 + (2^14-18)/4 + ((2^14-18)/4)^2 ~= 2^24
- *
- * Thus the max serialized object size is: 2^24*(2^14-18) ~= 256GB.
- *
- * The root directory "physicalMapping" is held in memory for performance,
- * but could itself be switched to using a block map. It will grow in
- * proportion to the number of tables/tuplebuffers in use.
- *
- * TODO: defragment
- * TODO: lobs could also be supported in this structure.
+ * There is unfortunately a significant memory footprint per group.
*/
-public class FileStoreCache implements Cache, StorageManager {
+public class FileStoreCache implements Cache {
- //TODO allow the block size to be configurable
- static final int LOG_BLOCK_SIZE = 14;
- static final int ADDRESS_BITS = 31;
- static final int SYSTEM_MASK = 1<<ADDRESS_BITS;
- static final int BLOCK_SIZE = 1 << LOG_BLOCK_SIZE;
- static final int BLOCK_MASK = BLOCK_SIZE - 1;
- static final int BLOCK_OVERHEAD = 8+8+3;
- static final int BLOCK_DATA_BYTES = BLOCK_SIZE - BLOCK_OVERHEAD;
- static final int BYTES_PER_BLOCK_ADDRESS = 4;
- static final int ADDRESSES_PER_BLOCK = BLOCK_DATA_BYTES/BYTES_PER_BLOCK_ADDRESS;
- static final int INODE_BYTES = 16*BYTES_PER_BLOCK_ADDRESS;
- static final int DIRECT_POINTERS = 14;
- static final int MAX_INDIRECT = DIRECT_POINTERS + ADDRESSES_PER_BLOCK;
- static final int MAX_DOUBLE_INDIRECT = MAX_INDIRECT + ADDRESSES_PER_BLOCK * ADDRESSES_PER_BLOCK;
- static final int EMPTY_ADDRESS = -1;
-
- private final class BlockOutputStream extends
- ExtensibleBufferedOutputStream {
- private final BlockManager blockManager;
- int blockNum = -1;
- BlockInfo bi;
-
- private BlockOutputStream(BlockManager blockManager) {
- this.blockManager = blockManager;
- }
-
- @Override
- protected ByteBuffer newBuffer() {
- bi = blockManager.allocateBlock(++blockNum);
- return bi.buf;
- }
-
- @Override
- protected void flushDirect() throws IOException {
- blockManager.updateBlock(bi);
- bi = null;
- }
- }
-
- private final class BitSetBlockManager implements BlockManager {
- final int offset;
+ private static class CacheGroup {
+ private static final int MAX_FREE_SPACE = 1 << 11;
+ FileStore store;
+ long tail;
+ long unusedSpace = 0;
+ ReadWriteLock lock = new ReentrantReadWriteLock();
+ Map<Long, long[]> physicalMapping = Collections.synchronizedMap(new HashMap<Long, long[]>());
+ List<Long> freed = Collections.synchronizedList(new LinkedList<Long>());
- BitSetBlockManager(int offset) {
- this.offset = offset;
+ CacheGroup(FileStore store) {
+ this.store = store;
}
- @Override
- public void updateBlock(BlockInfo info) {
- updatePhysicalBlock(info);
- }
-
- @Override
- public BlockInfo getBlock(int index) {
- return getPhysicalBlock(index + offset, true, false);
- }
-
- @Override
- public BlockInfo allocateBlock(int index) {
- return getPhysicalBlock(index + offset, true, true);
- }
-
- @Override
- public int getInode() {
- throw new AssertionError();
- }
-
- @Override
- public void freeBlock(int index) {
- throw new AssertionError();
- }
-
- @Override
- public void free() {
- throw new AssertionError();
- }
-
- }
-
- private enum Mode {
- GET,
- UPDATE,
- ALLOCATE
- }
-
- static final class BlockInfo {
- final boolean system;
- final int inodeOffset;
- final ByteBuffer buf;
- final int physicalAddress;
- boolean dirty;
-
- BlockInfo(boolean system, ByteBuffer ib, int index, int inodeOffset) {
- this.system = system;
- this.buf = ib;
- this.physicalAddress = index;
- this.inodeOffset = inodeOffset;
- }
- }
-
- private final class InodeBlockManager implements BlockManager {
- private final int inode;
- private final long gid;
- private final long oid;
- private int lastBlock = -1;
- boolean trackLast;
-
- InodeBlockManager(long gid, long oid, int inode) {
- if (inode == EMPTY_ADDRESS) {
- synchronized (inodesInuse) {
- inode = inodesInuse.nextClearBit(0);
- if (inode == -1) {
- throw new TeiidRuntimeException("no inodes available"); //$NON-NLS-1$
+ void freeBatch(Long batch) throws IOException {
+ long[] info = physicalMapping.remove(batch);
+ if (info != null) {
+ if (info[0] + info[1] == tail) {
+ tail -= info[1];
+ if (store.getLength() - tail > IO_BUFFER_SIZE << 5) {
+ store.setLength(tail);
}
- if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.TRACE)) {
- LogManager.logTrace(LogConstants.CTX_DQP, "Allocating inode", inode, "to", gid, oid); //$NON-NLS-1$ //$NON-NLS-2$
- }
- inodesInuse.set(inode, true);
+ } else {
+ unusedSpace += info[1];
}
- int inodeBlock = inode/inodesPerBlock;
- int inodePosition = INODE_BYTES*(inode%inodesPerBlock);
- BlockInfo bb = getInodeSubBlock(inodeBlock, inodePosition);
- bb.buf.putInt(EMPTY_ADDRESS);
- updatePhysicalBlock(bb);
}
- this.inode = inode;
- this.gid = gid;
- this.oid = oid;
}
- @Override
- public int getInode() {
- return inode;
- }
-
- @Override
- public void updateBlock(BlockInfo info) {
- updatePhysicalBlock(info);
- }
-
- @Override
- public BlockInfo getBlock(int index) {
- int dataBlock = getOrUpdateDataBlockIndex(index, EMPTY_ADDRESS, Mode.GET);
- BlockInfo bb = getPhysicalBlock(dataBlock, false, false);
- bb.buf.position(0);
- bb.buf.limit(BLOCK_DATA_BYTES);
- return bb;
- }
-
- private int getOrUpdateDataBlockIndex(int index, int value, Mode mode) {
- if (index >= MAX_DOUBLE_INDIRECT) {
- throw new TeiidRuntimeException("Max block number exceeded"); //$NON-NLS-1$
+ private long getOffset(Long gid, long compactionThreshold) throws IOException {
+ long currentLength = store.getLength();
+ if (currentLength <= compactionThreshold || unusedSpace * 4 <= currentLength * 3) {
+ return tail;
}
- int dataBlock = 0;
- int position = 0;
- int inodePosition = INODE_BYTES*(inode%inodesPerBlock);
- BlockInfo info = getInodeSubBlock(inode/inodesPerBlock, inodePosition);
- if (index >= MAX_INDIRECT) {
- position = BYTES_PER_BLOCK_ADDRESS*(DIRECT_POINTERS+1);
- BlockInfo next = updateIndirectBlockInfo(info, index, position, MAX_INDIRECT, MAX_DOUBLE_INDIRECT+1, value, mode);
- if (next != info) {
- info = next;
- //should have traversed to the secondary
- int indirectAddressBlock = (index - MAX_INDIRECT) / ADDRESSES_PER_BLOCK;
- position = indirectAddressBlock * BYTES_PER_BLOCK_ADDRESS;
- if (mode == Mode.ALLOCATE && position + BYTES_PER_BLOCK_ADDRESS < BLOCK_DATA_BYTES) {
- info.buf.putInt(position + BYTES_PER_BLOCK_ADDRESS, EMPTY_ADDRESS);
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
+ LogManager.logDetail(LogConstants.CTX_DQP, "Running full compaction on", gid); //$NON-NLS-1$
+ }
+ byte[] buffer = new byte[IO_BUFFER_SIZE];
+ TreeSet<long[]> bySize = new TreeSet<long[]>(new Comparator<long[]>() {
+ @Override
+ public int compare(long[] o1, long[] o2) {
+ int signum = Long.signum(o1[1] - o2[1]);
+ if (signum == 0) {
+ //take the upper address first
+ return Long.signum(o2[0] - o1[0]);
}
- next = updateIndirectBlockInfo(info, index, position, MAX_INDIRECT + indirectAddressBlock * ADDRESSES_PER_BLOCK, MAX_DOUBLE_INDIRECT + 2 + indirectAddressBlock, value, mode);
- if (next != info) {
- info = next;
- position = ((index - MAX_INDIRECT)%ADDRESSES_PER_BLOCK) * BYTES_PER_BLOCK_ADDRESS;
- if (mode == Mode.ALLOCATE && position + BYTES_PER_BLOCK_ADDRESS < BLOCK_DATA_BYTES) {
- info.buf.putInt(position + BYTES_PER_BLOCK_ADDRESS, EMPTY_ADDRESS);
- }
+ return signum;
+ }
+ });
+ TreeSet<long[]> byAddress = new TreeSet<long[]>(new Comparator<long[]>() {
+
+ @Override
+ public int compare(long[] o1, long[] o2) {
+ return Long.signum(o1[0] - o2[0]);
+ }
+ });
+ synchronized (physicalMapping) {
+ for (long[] value : physicalMapping.values()) {
+ if (value == null) {
+ continue;
}
+ bySize.add(value);
+ byAddress.add(value);
}
- } else if (index >= DIRECT_POINTERS) {
- //indirect
- position = BYTES_PER_BLOCK_ADDRESS*DIRECT_POINTERS;
- BlockInfo next = updateIndirectBlockInfo(info, index, position, DIRECT_POINTERS, MAX_DOUBLE_INDIRECT, value, mode);
- if (next != info) {
- info = next;
- position = (index - DIRECT_POINTERS) * BYTES_PER_BLOCK_ADDRESS;
- if (mode == Mode.ALLOCATE && position + BYTES_PER_BLOCK_ADDRESS < BLOCK_DATA_BYTES) {
- info.buf.putInt(position + BYTES_PER_BLOCK_ADDRESS, EMPTY_ADDRESS);
+ }
+ long lastEndAddress = 0;
+ long usedSpace = tail - unusedSpace;
+ while (!byAddress.isEmpty()) {
+ long[] info = byAddress.pollFirst();
+ bySize.remove(info);
+
+ long currentOffset = info[0];
+ long space = currentOffset - lastEndAddress;
+ boolean movedLast = false;
+ while (space > 0 && !bySize.isEmpty()) {
+ long[] last = byAddress.last();
+ if (last[1] > space) {
+ break;
}
+ movedLast = true;
+ byAddress.pollLast();
+ bySize.remove(last);
+ move(last, lastEndAddress, buffer);
+ space -= last[1];
+ lastEndAddress += last[1];
}
- } else {
- position = BYTES_PER_BLOCK_ADDRESS*index;
- if (mode == Mode.ALLOCATE) {
- info.buf.putInt(position + BYTES_PER_BLOCK_ADDRESS, EMPTY_ADDRESS);
+ if (movedLast && !byAddress.isEmpty()) {
+ long[] last = byAddress.last();
+ long currentLastEndAddress = last[0] + last[1];
+ if (currentLastEndAddress < currentLength>>1) {
+ lastEndAddress = currentLastEndAddress;
+ break;
+ }
}
- }
- if (mode == Mode.ALLOCATE) {
- dataBlock = nextBlock();
- info.buf.putInt(position, dataBlock);
- updatePhysicalBlock(info);
- } else {
- dataBlock = info.buf.getInt(position);
- if (mode == Mode.UPDATE) {
- info.buf.putInt(position, value);
- updatePhysicalBlock(info);
+ while (space > 0 && !bySize.isEmpty()) {
+ long[] smallest = bySize.first();
+ if (smallest[1] > space) {
+ break;
+ }
+ bySize.pollFirst();
+ byAddress.remove(smallest);
+ move(smallest, lastEndAddress, buffer);
+ space -= smallest[1];
+ lastEndAddress += smallest[1];
}
- }
- return dataBlock;
- }
-
- private BlockInfo updateIndirectBlockInfo(BlockInfo info, int index, int position, int cutOff, int blockId, int value, Mode mode) {
- int sib_index = info.buf.getInt(position);
- boolean newBlock = false;
- if (index == cutOff) {
- if (mode == Mode.ALLOCATE) {
- sib_index = nextBlock();
- info.buf.putInt(position, sib_index);
- updatePhysicalBlock(info);
- newBlock = true;
- } else if (mode == Mode.UPDATE && value == EMPTY_ADDRESS) {
- freeDataBlock(sib_index);
- return info;
+
+ if (space > MAX_FREE_SPACE) {
+ move(info, lastEndAddress, buffer);
}
+ lastEndAddress = info[0] + info[1];
}
- info = getPhysicalBlock(sib_index, false, false);
- if (newBlock) {
- putBlockId(blockId, info.buf);
+ store.setLength(lastEndAddress);
+ tail = lastEndAddress;
+ unusedSpace = lastEndAddress - usedSpace;
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
+ LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Compacted store", gid, "pre-size", currentLength, "post-size", lastEndAddress); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- return info;
+ return tail;
}
-
- private int nextBlock() {
- int next = -1;
- synchronized (blocksInuse) {
- next = blocksInuse.nextClearBit(lastBlock + 1);
- if (next == -1) {
- throw new TeiidRuntimeException("no freespace available"); //$NON-NLS-1$
- }
- blocksInuse.set(next, true);
- }
- if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.TRACE)) {
- LogManager.logTrace(LogConstants.CTX_DQP, "Allocating block", next, "to", gid, oid); //$NON-NLS-1$ //$NON-NLS-2$
- }
- if (trackLast) {
- lastBlock = next;
- }
- return next;
- }
-
- @Override
- public void freeBlock(int index) {
- int dataBlock = getOrUpdateDataBlockIndex(index, EMPTY_ADDRESS, Mode.UPDATE);
- freeDataBlock(dataBlock);
- }
-
- private void freeDataBlock(int dataBlock) {
- if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.TRACE)) {
- LogManager.logTrace(LogConstants.CTX_DQP, "freeing data block", dataBlock, "for", gid, oid); //$NON-NLS-1$ //$NON-NLS-2$
- }
- blockCache.remove(dataBlock);
- blocksInuse.set(dataBlock, false);
- }
- BlockInfo getInodeSubBlock(int inodeBlock, int inodePosition) {
- BlockInfo bi = getPhysicalBlock(inodeBlock + blocksInUseBlocks + inodesInUseBlocks, true, false);
- ByteBuffer bb = bi.buf.duplicate();
- bb.position(inodePosition);
- bb.limit(inodePosition + INODE_BYTES);
- bb = bb.slice();
- return new BlockInfo(true, bb, inodeBlock + blocksInUseBlocks + inodesInUseBlocks, inodePosition);
- }
-
- @Override
- public void free() {
- int inodeBlock = inode/inodesPerBlock;
- int inodePosition = INODE_BYTES*(inode%inodesPerBlock);
- BlockInfo bi = getInodeSubBlock(inodeBlock, inodePosition);
- ByteBuffer ib = bi.buf;
- int indirectIndexBlock = ib.getInt(ib.position() + BYTES_PER_BLOCK_ADDRESS*DIRECT_POINTERS);
- int doublyIndirectIndexBlock = ib.getInt(ib.position() + BYTES_PER_BLOCK_ADDRESS*(DIRECT_POINTERS+1));
- boolean freedAll = freeBlock(ib, DIRECT_POINTERS, true);
- if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.TRACE)) {
- LogManager.logTrace(LogConstants.CTX_DQP, "freeing inode", inode, "for", gid, oid); //$NON-NLS-1$ //$NON-NLS-2$
+ private void move(long[] toMove, long newOffset, byte[] buffer) throws IOException {
+ long oldOffset = toMove[0];
+ toMove[0] = newOffset;
+ int size = (int)toMove[1];
+ while (size > 0) {
+ int toWrite = Math.min(IO_BUFFER_SIZE, size);
+ store.readFully(oldOffset, buffer, 0, toWrite);
+ store.write(newOffset, buffer, 0, toWrite);
+ size -= toWrite;
+ oldOffset += toWrite;
+ newOffset += toWrite;
}
- inodesInuse.set(inode, false);
- if (!freedAll || indirectIndexBlock == EMPTY_ADDRESS) {
- return;
- }
- freedAll = freeIndirectBlock(indirectIndexBlock);
- if (!freedAll || doublyIndirectIndexBlock == EMPTY_ADDRESS) {
- return;
- }
- BlockInfo bb = getPhysicalBlock(doublyIndirectIndexBlock, false, false);
- freeBlock(bb.buf, ADDRESSES_PER_BLOCK, false);
- freeDataBlock(doublyIndirectIndexBlock);
}
-
- private boolean freeIndirectBlock(int indirectIndexBlock) {
- BlockInfo bb = getPhysicalBlock(indirectIndexBlock, false, false);
- bb.buf.position(0);
- boolean freedAll = freeBlock(bb.buf, ADDRESSES_PER_BLOCK, true);
- freeDataBlock(indirectIndexBlock);
- return freedAll;
- }
-
- private boolean freeBlock(ByteBuffer ib, int numPointers, boolean primary) {
- for (int i = 0; i < numPointers; i++) {
- int dataBlock = ib.getInt();
- if (dataBlock == EMPTY_ADDRESS) {
- return false;
- }
- if (primary) {
- freeDataBlock(dataBlock);
- } else {
- freeIndirectBlock(dataBlock);
- }
- }
- return true;
- }
-
- @Override
- public BlockInfo allocateBlock(int blockNum) {
- int dataBlock = getOrUpdateDataBlockIndex(blockNum, EMPTY_ADDRESS, Mode.ALLOCATE);
- BlockInfo bb = getPhysicalBlock(dataBlock, false, true);
- putBlockId(blockNum, bb.buf);
- bb.buf.position(0);
- bb.buf.limit(BLOCK_DATA_BYTES);
- return bb;
- }
-
- private void putBlockId(int blockNum, ByteBuffer bb) {
- bb.position(BLOCK_DATA_BYTES);
- bb.putLong(gid);
- bb.putLong(oid);
- bb.put((byte)(blockNum >> 16));
- bb.putShort((short)blockNum);
- }
-
}
+ private static final int COMPACTION_THRESHOLD = 1 << 24; //start checking at 16 megs
+ private static final int IO_BUFFER_SIZE = 1<<13;
+ int compactionThreshold = COMPACTION_THRESHOLD;
+ private ConcurrentHashMap<Long, CacheGroup> cacheGroups = new ConcurrentHashMap<Long, CacheGroup>();
private StorageManager storageManager;
- private long maxBufferSpace = FileStorageManager.DEFAULT_MAX_BUFFERSPACE;
- private int inodes;
- private int blocks;
- private int inodesPerBlock;
- private int inodesInUseBlocks;
- private int blocksInUseBlocks;
- private FileStore store;
- private FileStore systemStore;
- private BlockBitSetTree blocksInuse;
- private BlockBitSetTree inodesInuse;
-
- //root directory
- ConcurrentHashMap<Long, BlockClosedLongIntHashTable> physicalMapping = new ConcurrentHashMap<Long, BlockClosedLongIntHashTable>();
- //block caching
- int blockCacheSize = 128; //2 MB
- ReentrantLock blockLock = new ReentrantLock();
- LinkedHashMap<Integer, BlockInfo> blockCache = new LinkedHashMap<Integer, BlockInfo>() {
- private static final long serialVersionUID = -4240291744435552008L;
- BlockInfo eldestEntry = null;
+ @Override
+ public void add(CacheEntry entry, Serializer s) throws Exception {
+ final CacheGroup group = cacheGroups.get(s.getId());
+ if (group == null) {
+ return;
+ }
- protected boolean removeEldestEntry(Map.Entry<Integer,BlockInfo> eldest) {
- if (size() > blockCacheSize) {
- BlockInfo bi = eldest.getValue();
- if (bi.dirty) {
- eldestEntry = bi;
+ group.lock.writeLock().lock();
+ try {
+ synchronized (group.freed) {
+ while (!group.freed.isEmpty()) {
+ group.freeBatch(group.freed.remove(0));
}
- return true;
}
- return false;
- }
-
- public BlockInfo put(Integer key, BlockInfo value) {
- blockLock.lock();
- value.dirty = true;
- try {
- return super.put(key, value);
- } finally {
- BlockInfo toUpdate = eldestEntry;
- eldestEntry = null;
- blockLock.unlock();
- if (toUpdate != null) {
- updatePhysicalBlockDirect(toUpdate);
+ final ByteBuffer buffer = ByteBuffer.allocate(IO_BUFFER_SIZE);
+ final long offset = group.getOffset(s.getId(), compactionThreshold);
+ ExtensibleBufferedOutputStream fsos = new ExtensibleBufferedOutputStream() {
+ @Override
+ protected ByteBuffer newBuffer() {
+ buffer.rewind();
+ return buffer;
}
- }
- }
-
- public BlockInfo get(Object key) {
- blockLock.lock();
- try {
- return super.get(key);
- } finally {
- blockLock.unlock();
- }
- }
-
- public BlockInfo remove(Object key) {
- blockLock.lock();
- try {
- return super.remove(key);
- } finally {
- blockLock.unlock();
- }
- }
- };
-
- BlockInfo getPhysicalBlock(int block, boolean system, boolean allocate) {
- if (block < 0) {
- throw new AssertionError("invalid block address " + block); //$NON-NLS-1$
- }
- try {
- int key = block;
- if (system) {
- key |= SYSTEM_MASK;
- }
- BlockInfo result = blockCache.get(key);
- assert result == null || !allocate;
- if (result == null) {
- ByteBuffer bb = null;
- if (system) {
- bb = systemStore.getBuffer(block<<LOG_BLOCK_SIZE, BLOCK_SIZE, allocate);
- } else {
- bb = store.getBuffer(block<<LOG_BLOCK_SIZE, BLOCK_SIZE, allocate);
+
+ @Override
+ protected int flushDirect() throws IOException {
+ group.store.write(offset + bytesWritten, buffer.array(), 0, buf.position());
+ return buf.position();
}
- result = new BlockInfo(system, bb, block, -1);
- blockLock.lock();
- try {
- BlockInfo existing = blockCache.get(key);
- if (existing != null) {
- return existing;
- }
- blockCache.put(key, result);
- } finally {
- blockLock.unlock();
- }
- return result;
+ };
+ ObjectOutputStream oos = new ObjectOutputStream(fsos);
+ oos.writeInt(entry.getSizeEstimate());
+ s.serialize(entry.getObject(), oos);
+ oos.close();
+ long size = fsos.getBytesWritten();
+ long[] info = new long[] {offset, size};
+ group.physicalMapping.put(entry.getId(), info);
+ group.tail = Math.max(group.tail, offset + size);
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
+ LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, s.getId(), entry.getId(), "batch written starting at:", offset); //$NON-NLS-1$
}
- return result;
- } catch (IOException e) {
- throw new TeiidRuntimeException(e);
+ } finally {
+ group.lock.writeLock().unlock();
}
}
-
- void updatePhysicalBlock(BlockInfo bi) {
- int key = bi.physicalAddress;
- if (bi.system) {
- key |= SYSTEM_MASK;
- }
- if (bi.inodeOffset >= 0) {
- blockLock.lock();
- try {
- BlockInfo actual = blockCache.get(key);
- if (actual == null) {
- //we're not in the cache, so just update storage
- updatePhysicalBlockDirect(bi);
- } else {
- //TODO: check to see we're sharing the same buffer
- for (int i = 0; i < INODE_BYTES; i++) {
- actual.buf.put(bi.inodeOffset + i, bi.buf.get(i));
- }
- }
- } finally {
- blockLock.unlock();
- }
- return;
- }
- blockCache.put(key, bi);
- }
- private void updatePhysicalBlockDirect(BlockInfo bi) {
- try {
- bi.buf.rewind();
- if (!bi.system) {
- store.updateFromBuffer(bi.buf, bi.physicalAddress<<LOG_BLOCK_SIZE);
- } else {
- systemStore.updateFromBuffer(bi.buf, bi.physicalAddress<<LOG_BLOCK_SIZE);
- }
- } catch (IOException e) {
- throw new TeiidRuntimeException(e);
- }
- }
-
- InodeBlockManager getBlockManager(long gid, long oid, int inode) {
- return new InodeBlockManager(gid, oid, inode);
- }
-
- @SuppressWarnings("unchecked")
@Override
- public void add(CacheEntry entry, Serializer s) {
- boolean success = false;
- InodeBlockManager blockManager = null;
- try {
- BlockClosedLongIntHashTable map = physicalMapping.get(s.getId());
- if (map == null) {
- return;
- }
- blockManager = getBlockManager(s.getId(), entry.getId(), EMPTY_ADDRESS);
- blockManager.trackLast = true;
- ExtensibleBufferedOutputStream fsos = new BlockOutputStream(blockManager);
- ObjectOutputStream oos = new ObjectOutputStream(fsos);
- oos.writeInt(entry.getSizeEstimate());
- s.serialize(entry.getObject(), oos);
- oos.close();
- map.put(entry.getId(), blockManager.getInode());
- success = true;
- } catch (Throwable e) {
- LogManager.logError(LogConstants.CTX_BUFFER_MGR, e, "Error persisting batch, attempts to read batch "+ entry.getId() +" later will result in an exception"); //$NON-NLS-1$ //$NON-NLS-2$
- } finally {
- if (!success && blockManager != null) {
- blockManager.free();
- }
- }
+ public void createCacheGroup(Long gid) {
+ cacheGroups.put(gid, new CacheGroup(storageManager.createFileStore(String.valueOf(gid))));
}
@Override
- public CacheEntry get(Long oid, Serializer<?> serializer) throws TeiidComponentException {
+ public CacheEntry get(Long id, Serializer<?> serializer)
+ throws TeiidComponentException {
+ CacheGroup group = cacheGroups.get(serializer.getId());
+ if (group == null) {
+ return null;
+ }
try {
- BlockClosedLongIntHashTable map = physicalMapping.get(serializer.getId());
- if (map == null) {
+ group.lock.readLock().lock();
+ long[] info = group.physicalMapping.get(id);
+ if (info == null) {
return null;
}
- final int inode = map.get(oid);
- if (inode == EMPTY_ADDRESS) {
- return null;
- }
- final BlockManager manager = getBlockManager(serializer.getId(), oid, inode);
- ObjectInputStream ois = new ObjectInputStream(new InputStream() {
-
- int blockIndex;
- BlockInfo buf;
-
- @Override
- public int read() throws IOException {
- ensureBytes();
- return buf.buf.get() & 0xff;
- }
-
- private void ensureBytes() {
- if (buf == null || buf.buf.remaining() == 0) {
- if (buf != null) {
- buf = null;
- }
- buf = manager.getBlock(blockIndex++);
- }
- }
-
- @Override
- public int read(byte[] b, int off, int len)
- throws IOException {
- ensureBytes();
- len = Math.min(len, buf.buf.remaining());
- buf.buf.get(b, off, len);
- return len;
- }
- });
- CacheEntry ce = new CacheEntry(oid);
+ ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(group.store.createInputStream(info[0]), IO_BUFFER_SIZE));
+ CacheEntry ce = new CacheEntry(id);
ce.setSizeEstimate(ois.readInt());
ce.setObject(serializer.deserialize(ois));
- ce.setPersistent(true);
return ce;
} catch(IOException e) {
- throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", oid)); //$NON-NLS-1$
+ throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", id)); //$NON-NLS-1$
} catch (ClassNotFoundException e) {
- throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", oid)); //$NON-NLS-1$
+ throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", id)); //$NON-NLS-1$
+ } finally {
+ group.lock.readLock().unlock();
}
}
-
- @Override
- public FileStore createFileStore(String name) {
- return storageManager.createFileStore(name);
- }
-
- @Override
- public void initialize() throws TeiidComponentException {
- storageManager.initialize();
- int logSpace = Math.min(45, 63 - Long.numberOfLeadingZeros(this.maxBufferSpace));
-
- blocks = 1 << Math.min(Math.max(12, logSpace -LOG_BLOCK_SIZE +1), ADDRESS_BITS); //blocks per segment
- inodes = blocks>>1;
- inodesPerBlock = BLOCK_SIZE/INODE_BYTES;
-
- inodesInUseBlocks = computeInuseBlocks(inodes);
- blocksInUseBlocks = computeInuseBlocks(blocks);
-
- inodesInuse = new BlockBitSetTree(inodes - 1, new BitSetBlockManager(0));
- blocksInuse = new BlockBitSetTree(blocks - 1, new BitSetBlockManager(inodesInUseBlocks));
-
- store = storageManager.createFileStore("data_store"); //$NON-NLS-1$
- systemStore = storageManager.createFileStore("system_store"); //$NON-NLS-1$
- }
-
- static int computeInuseBlocks(int number) {
- int blockCount = (number>>LOG_BLOCK_SIZE) + ((number&BLOCK_MASK)>0?1:0);
- return (blockCount>>3) + ((blockCount&7)>0?1:0);
- }
-
@Override
- public void addToCacheGroup(Long gid, Long oid) {
- BlockClosedLongIntHashTable map = physicalMapping.get(gid);
- if (map == null) {
+ public void remove(Long gid, Long id) {
+ CacheGroup group = cacheGroups.get(gid);
+ if (group == null) {
return;
}
- map.put(oid, EMPTY_ADDRESS);
+ if (group.lock.writeLock().tryLock()) {
+ try {
+ try {
+ group.freeBatch(id);
+ } catch (IOException e) {
+ LogManager.logError(LogConstants.CTX_BUFFER_MGR, e, "Error removing batch"); //$NON-NLS-1$
+ }
+ } finally {
+ group.lock.writeLock().unlock();
+ }
+ } else {
+ group.freed.add(id);
+ }
}
@Override
- public void createCacheGroup(Long gid) {
- BlockClosedLongIntHashTable map = new BlockClosedLongIntHashTable(getBlockManager(gid, -1, EMPTY_ADDRESS));
- physicalMapping.put(gid, map);
- }
-
- @Override
- public void remove(Long gid, Long id) {
- BlockClosedLongIntHashTable map = physicalMapping.get(gid);
- if (map == null) {
+ public void addToCacheGroup(Long gid, Long oid) {
+ CacheGroup group = cacheGroups.get(gid);
+ if (group == null) {
return;
}
- int inode = map.remove(id);
- free(gid, id, inode);
+ group.physicalMapping.put(oid, null);
}
@Override
public Collection<Long> removeCacheGroup(Long gid) {
- BlockClosedLongIntHashTable map = physicalMapping.remove(gid);
- if (map == null) {
- return Collections.emptySet();
+ CacheGroup group = cacheGroups.remove(gid);
+ if (group == null) {
+ return Collections.emptyList();
}
- Map<Long, Integer> values = map.remove();
- for (Map.Entry<Long, Integer> entry : values.entrySet()) {
- if (entry.getValue() != null) {
- free(gid, entry.getKey(), entry.getValue());
- }
+ group.store.remove();
+ synchronized (group.physicalMapping) {
+ return new ArrayList<Long>(group.physicalMapping.keySet());
}
- return values.keySet();
}
-
- void free(Long gid, Long oid, int inode) {
- if (inode == EMPTY_ADDRESS) {
- return;
- }
- BlockManager bm = getBlockManager(gid, oid, inode);
- bm.free();
+
+ @Override
+ public FileStore createFileStore(String name) {
+ return storageManager.createFileStore(name);
}
+
+ @Override
+ public void initialize() throws TeiidComponentException {
+ this.storageManager.initialize();
+ }
public void setStorageManager(StorageManager storageManager) {
this.storageManager = storageManager;
@@ -731,16 +341,8 @@
return storageManager;
}
- public void setMaxBufferSpace(long maxBufferSpace) {
- this.maxBufferSpace = maxBufferSpace;
+ public void setCompactionThreshold(int compactionThreshold) {
+ this.compactionThreshold = compactionThreshold;
}
-
- public int getInodesInUse() {
- return this.inodesInuse.getBitsSet();
- }
-
- public int getDataBlocksInUse() {
- return this.blocksInuse.getBitsSet();
- }
-
+
}
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/MemoryStorageManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/MemoryStorageManager.java 2011-09-29 16:46:38 UTC (rev 3507)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/MemoryStorageManager.java 2011-09-30 02:00:28 UTC (rev 3508)
@@ -22,7 +22,6 @@
package org.teiid.common.buffer.impl;
-import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collection;
@@ -87,20 +86,6 @@
public synchronized long getLength() {
return buffer.limit();
}
-
- @Override
- public synchronized ByteBuffer getBuffer(long start, int length, boolean allocate) {
- int position = (int)start;
- buffer.limit(position + length);
- buffer.position(position);
- return buffer.slice();
- }
-
- @Override
- public void updateFromBuffer(ByteBuffer bb, long start)
- throws IOException {
- //do nothing we are sharing the bytes
- }
}
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java 2011-09-29 16:46:38 UTC (rev 3507)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java 2011-09-30 02:00:28 UTC (rev 3508)
@@ -23,7 +23,6 @@
package org.teiid.common.buffer.impl;
import java.io.IOException;
-import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
@@ -79,7 +78,7 @@
FileStore store = null;
if (!write) {
synchronized (this) {
- if (fileOffset + length > len) {
+ if (fileOffset > len) {
throw new IOException("Invalid file position " + fileOffset + " length " + length); //$NON-NLS-1$ //$NON-NLS-2$
}
store = storageFiles.get((int)(fileOffset/maxFileSize));
@@ -118,28 +117,6 @@
len = length;
}
- @Override
- public ByteBuffer getBuffer(long start, int length, boolean allocate) throws IOException {
- FileStore store = null;
- synchronized (this) {
- ensureLength(start + length);
- store = storageFiles.get((int)(start/maxFileSize));
- }
- long fileBegin = start%maxFileSize;
- return store.getBuffer(fileBegin, length, allocate);
- }
-
- @Override
- public void updateFromBuffer(ByteBuffer bb, long start)
- throws IOException {
- FileStore store = null;
- synchronized (this) {
- store = storageFiles.get((int)(start/maxFileSize));
- }
- long fileBegin = start%maxFileSize;
- store.updateFromBuffer(bb, fileBegin);
- }
-
@Override
public synchronized void setLength(long length) throws IOException {
if (length > len) {
Modified: trunk/engine/src/test/java/org/teiid/common/buffer/BufferManagerFactory.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/BufferManagerFactory.java 2011-09-29 16:46:38 UTC (rev 3507)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/BufferManagerFactory.java 2011-09-30 02:00:28 UTC (rev 3508)
@@ -86,7 +86,6 @@
SplittableStorageManager ssm = new SplittableStorageManager(storageManager);
ssm.setMaxFileSizeDirect(MemoryStorageManager.MAX_FILE_SIZE);
FileStoreCache fsc = new FileStoreCache();
- fsc.setMaxBufferSpace(Runtime.getRuntime().maxMemory()/4);
fsc.setStorageManager(ssm);
fsc.initialize();
bufferManager.setCache(fsc);
Modified: trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java 2011-09-29 16:46:38 UTC (rev 3507)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java 2011-09-30 02:00:28 UTC (rev 3508)
@@ -30,6 +30,7 @@
import org.junit.Test;
import org.teiid.common.buffer.STree.InsertMode;
import org.teiid.common.buffer.impl.BufferManagerImpl;
+import org.teiid.common.buffer.impl.FileStoreCache;
import org.teiid.core.TeiidComponentException;
import org.teiid.query.sql.symbol.ElementSymbol;
@@ -109,6 +110,7 @@
BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
bm.setProcessorBatchSize(32);
bm.setMaxReserveKB(0);//force all to disk
+ ((FileStoreCache)bm.getCache()).setCompactionThreshold(0);
bm.initialize();
ElementSymbol e1 = new ElementSymbol("x");
Deleted: trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockBitSetTree.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockBitSetTree.java 2011-09-29 16:46:38 UTC (rev 3507)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockBitSetTree.java 2011-09-30 02:00:28 UTC (rev 3508)
@@ -1,66 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library 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 library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
- package org.teiid.common.buffer.impl;
-
-import static org.junit.Assert.*;
-
-import java.util.BitSet;
-import java.util.Random;
-
-import org.junit.Test;
-
-public class TestBlockBitSetTree {
-
- @Test public void testBitsSet() {
- BlockBitSetTree bst = new BlockBitSetTree((1 << 20) -1, new TestBlockClosedLongIntHashTable.DummyBlockManager());
- bst.set(1, true);
- bst.set(100, true);
- bst.set(10000, true);
- bst.set(1000000, true);
- assertEquals(4, bst.getBitsSet());
- bst.set(1, false);
- assertEquals(3, bst.getBitsSet());
- assertFalse(bst.get(1));
- }
-
- @Test public void testNextClearSet() {
- BlockBitSetTree bst = new BlockBitSetTree((1 << 20) -1, new TestBlockClosedLongIntHashTable.DummyBlockManager());
- BitSet bst1 = new BitSet();
- Random r = new Random(1);
- for (int i = 0; i < 1000; i++) {
- int rand = r.nextInt() & bst.getMaxIndex();
- bst.set(rand, true);
- bst1.set(rand, true);
- assertTrue(bst.get(rand));
- assertEquals(bst1.nextSetBit(rand), bst.nextSetBit(rand));
- assertEquals(String.valueOf(i), bst1.nextSetBit(rand), bst.nextSetBit(rand));
- }
-
- for (int i = 0; i < 10000; i++) {
- int rand = r.nextInt() & bst.getMaxIndex();
- assertEquals(bst1.nextClearBit(rand), bst.nextClearBit(rand));
- assertEquals(bst1.nextSetBit(rand), bst.nextSetBit(rand));
- }
- }
-
-}
Deleted: trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockClosedLongIntHashTable.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockClosedLongIntHashTable.java 2011-09-29 16:46:38 UTC (rev 3507)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockClosedLongIntHashTable.java 2011-09-30 02:00:28 UTC (rev 3508)
@@ -1,92 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library 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 library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.common.buffer.impl;
-
-import static org.junit.Assert.*;
-
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Random;
-
-import org.junit.Test;
-import org.teiid.common.buffer.impl.FileStoreCache.BlockInfo;
-
-public class TestBlockClosedLongIntHashTable {
-
- public static final class DummyBlockManager implements BlockManager {
- List<BlockInfo> blocks = new ArrayList<BlockInfo>();
-
- @Override
- public int getInode() {
- return 0;
- }
-
- @Override
- public void updateBlock(BlockInfo block) {
-
- }
-
- @Override
- public void free() {
- blocks.clear();
- }
-
- @Override
- public BlockInfo getBlock(int index) {
- BlockInfo block = blocks.get(index);
- block.buf.rewind();
- return block;
- }
-
- @Override
- public void freeBlock(int index) {
- blocks.remove(index);
- }
-
- @Override
- public BlockInfo allocateBlock(int index) {
- assertEquals(index, blocks.size());
- ByteBuffer result = ByteBuffer.wrap(new byte[FileStoreCache.BLOCK_SIZE]);
- blocks.add(new BlockInfo(false, result, index, -1));
- return blocks.get(blocks.size() - 1);
- }
- }
-
- @Test public void testAgainstHashMap() {
- BlockClosedLongIntHashTable table = new BlockClosedLongIntHashTable(new DummyBlockManager());
- HashMap<Long, Integer> table1 = new HashMap<Long, Integer>(16);
- for (long i = 1; i < 200000; i++) {
- table.put(i, (int)i);
- table1.put(i, (int)i);
- }
- Random r = new Random(0);
- for (int i = 1; i < 2000000; i++) {
- long toRemove = r.nextInt(i);
- boolean removed = table.remove(toRemove) != BlockClosedLongIntHashTable.EMPTY;
- assertEquals(table1.remove(toRemove) != null, removed);
- }
- }
-
-}
Deleted: trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStoreCache.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStoreCache.java 2011-09-29 16:46:38 UTC (rev 3507)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStoreCache.java 2011-09-30 02:00:28 UTC (rev 3508)
@@ -1,119 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library 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 library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.common.buffer.impl;
-
-import static org.junit.Assert.*;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-import org.junit.Test;
-import org.teiid.common.buffer.CacheEntry;
-import org.teiid.common.buffer.Serializer;
-import org.teiid.core.util.UnitTestUtil;
-
-public class TestFileStoreCache {
-
- private final class SimpleSerializer implements Serializer<Integer> {
- @Override
- public Integer deserialize(ObjectInputStream ois)
- throws IOException, ClassNotFoundException {
- Integer result = ois.readInt();
- for (int i = 0; i < result; i++) {
- assertEquals(i, ois.readInt());
- }
- return result;
- }
-
- @Override
- public Long getId() {
- return 1l;
- }
-
- @Override
- public void serialize(Integer obj, ObjectOutputStream oos)
- throws IOException {
- oos.writeInt(obj);
- for (int i = 0; i < obj; i++) {
- oos.writeInt(i);
- }
- }
-
- @Override
- public boolean useSoftCache() {
- return false;
- }
- }
-
- @Test public void testAddGetMultiBlock() throws Exception {
- FileStoreCache fsc = new FileStoreCache();
- fsc.setMaxBufferSpace(1 << 28);
- SplittableStorageManager ssm = new SplittableStorageManager(new MemoryStorageManager());
- ssm.setMaxFileSizeDirect(MemoryStorageManager.MAX_FILE_SIZE);
- fsc.setStorageManager(ssm);
- fsc.initialize();
-
- UnitTestUtil.enableTraceLogging("org.teiid"); //$NON-NLS-1$
-
- CacheEntry ce = new CacheEntry(2l);
- Serializer<Integer> s = new SimpleSerializer();
- fsc.createCacheGroup(s.getId());
- Integer cacheObject = Integer.valueOf(2);
- ce.setObject(cacheObject);
- fsc.add(ce, s);
-
- ce = fsc.get(2l, s);
- assertEquals(cacheObject, ce.getObject());
-
- //test something that exceeds the direct inode data blocks
- ce = new CacheEntry(3l);
- cacheObject = Integer.valueOf(80000);
- ce.setObject(cacheObject);
- fsc.add(ce, s);
-
- ce = fsc.get(3l, s);
- assertEquals(cacheObject, ce.getObject());
-
- fsc.removeCacheGroup(1l);
-
- assertEquals(0, fsc.getDataBlocksInUse());
- assertEquals(0, fsc.getInodesInUse());
-
- //test something that exceeds the indirect inode data blocks
- ce = new CacheEntry(3l);
- fsc.createCacheGroup(s.getId());
- cacheObject = Integer.valueOf(5000000);
- ce.setObject(cacheObject);
- fsc.add(ce, s);
-
- ce = fsc.get(3l, s);
- assertEquals(cacheObject, ce.getObject());
-
- fsc.removeCacheGroup(1l);
-
- assertEquals(0, fsc.getDataBlocksInUse());
- assertEquals(0, fsc.getInodesInUse());
- }
-
-}
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java 2011-09-29 16:46:38 UTC (rev 3507)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java 2011-09-30 02:00:28 UTC (rev 3508)
@@ -378,17 +378,17 @@
Future<ResultsMessage> message = core.executeRequest(reqMsg.getExecutionId(), reqMsg);
ResultsMessage rm = message.get(500000, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
- assertEquals(5, rm.getResults().length);
+ assertEquals(5, rm.getResultsList().size());
message = core.processCursorRequest(reqMsg.getExecutionId(), 6, 5);
rm = message.get(500000, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
- assertEquals(5, rm.getResults().length);
+ assertEquals(5, rm.getResultsList().size());
message = core.processCursorRequest(reqMsg.getExecutionId(), 11, 5);
rm = message.get(500000, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
- assertEquals(5, rm.getResults().length);
+ assertEquals(5, rm.getResultsList().size());
}
@Test public void testSourceConcurrency() throws Exception {
Modified: trunk/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java 2011-09-29 16:46:38 UTC (rev 3507)
+++ trunk/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java 2011-09-30 02:00:28 UTC (rev 3508)
@@ -108,7 +108,6 @@
ssm.setMaxFileSize(maxFileSize);
FileStoreCache fsc = new FileStoreCache();
fsc.setStorageManager(ssm);
- fsc.setMaxBufferSpace(maxBufferSpace*MB);
fsc.initialize();
this.bufferMgr.setCache(fsc);
} else {
[View Less]
13 years, 6 months
teiid SVN: r3507 - in branches/as7: adminshell/src/main/java/org/teiid/adminshell and 53 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2011-09-29 12:46:38 -0400 (Thu, 29 Sep 2011)
New Revision: 3507
Added:
branches/as7/engine/src/main/java/org/teiid/common/buffer/AutoCleanupUtil.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/Cache.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/CacheEntry.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/LightWeightCopyOnWriteList.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/Serializer.java
…
[View More]branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/BlockBitSetTree.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/BlockClosedLongIntHashTable.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/BlockManager.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/ExtensibleBufferedOutputStream.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/FileStoreCache.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java
branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/SerializableTupleBatch.java
branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockBitSetTree.java
branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockClosedLongIntHashTable.java
branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStoreCache.java
branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestSplittableStorageManager.java
Removed:
branches/as7/engine/src/test/java/org/teiid/core/
Modified:
branches/as7/
branches/as7/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java
branches/as7/api/src/main/java/org/teiid/CommandContext.java
branches/as7/api/src/main/java/org/teiid/events/EventDistributor.java
branches/as7/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml
branches/as7/build/kits/jboss-container/teiid-releasenotes.html
branches/as7/client/src/main/java/org/teiid/client/BatchSerializer.java
branches/as7/client/src/main/java/org/teiid/client/ResultsMessage.java
branches/as7/client/src/main/java/org/teiid/jdbc/ConnectionImpl.java
branches/as7/client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java
branches/as7/client/src/main/java/org/teiid/jdbc/EmbeddedProfile.java
branches/as7/client/src/main/java/org/teiid/jdbc/JDBCURL.java
branches/as7/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java
branches/as7/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java
branches/as7/client/src/main/java/org/teiid/jdbc/SQLStates.java
branches/as7/client/src/main/java/org/teiid/jdbc/StatementImpl.java
branches/as7/client/src/main/java/org/teiid/jdbc/TeiidSQLException.java
branches/as7/client/src/main/java/org/teiid/net/socket/SocketServerConnectionFactory.java
branches/as7/client/src/test/java/org/teiid/client/TestBatchSerializer.java
branches/as7/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java
branches/as7/client/src/test/java/org/teiid/jdbc/TestCallableStatement.java
branches/as7/client/src/test/java/org/teiid/jdbc/TestConnection.java
branches/as7/client/src/test/java/org/teiid/jdbc/TestSQLException.java
branches/as7/client/src/test/java/org/teiid/jdbc/TestStatement.java
branches/as7/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java
branches/as7/common-core/src/main/java/org/teiid/core/TeiidException.java
branches/as7/common-core/src/main/java/org/teiid/core/TeiidRuntimeException.java
branches/as7/common-core/src/main/java/org/teiid/core/types/BaseLob.java
branches/as7/common-core/src/main/java/org/teiid/core/types/BlobImpl.java
branches/as7/common-core/src/main/java/org/teiid/core/types/BlobType.java
branches/as7/common-core/src/main/java/org/teiid/core/types/ClobType.java
branches/as7/common-core/src/main/java/org/teiid/core/types/DataTypeManager.java
branches/as7/common-core/src/main/java/org/teiid/core/types/InputStreamFactory.java
branches/as7/common-core/src/main/java/org/teiid/core/types/SQLXMLImpl.java
branches/as7/common-core/src/main/java/org/teiid/core/types/Streamable.java
branches/as7/common-core/src/main/java/org/teiid/core/types/XMLType.java
branches/as7/common-core/src/main/resources/org/teiid/core/util/application.properties
branches/as7/common-core/src/test/java/org/teiid/core/TestMetaMatrixRuntimeException.java
branches/as7/common-core/src/test/java/org/teiid/core/types/TestBlobValue.java
branches/as7/common-core/src/test/java/org/teiid/core/types/TestClobValue.java
branches/as7/common-core/src/test/java/org/teiid/core/types/TestXMLValue.java
branches/as7/common-core/src/test/java/org/teiid/core/util/UnitTestUtil.java
branches/as7/documentation/caching-guide/src/main/docbook/en-US/content/hint-option.xml
branches/as7/engine/src/main/java/org/teiid/common/buffer/BatchManager.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/BlockedException.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/BufferManager.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/FileStore.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/FileStoreInputStreamFactory.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/LobManager.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/SPage.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/STree.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/TupleBatch.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/FileStorageManager.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/MemoryStorageManager.java
branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/SizeUtility.java
branches/as7/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java
branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java
branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
branches/as7/engine/src/main/java/org/teiid/dqp/message/AtomicResultsMessage.java
branches/as7/engine/src/main/java/org/teiid/query/function/FunctionDescriptor.java
branches/as7/engine/src/main/java/org/teiid/query/function/FunctionTree.java
branches/as7/engine/src/main/java/org/teiid/query/function/source/SecuritySystemFunctions.java
branches/as7/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
branches/as7/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java
branches/as7/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
branches/as7/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java
branches/as7/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java
branches/as7/engine/src/main/java/org/teiid/query/processor/relational/EnhancedSortMergeJoinStrategy.java
branches/as7/engine/src/main/java/org/teiid/query/processor/relational/NullNode.java
branches/as7/engine/src/main/java/org/teiid/query/processor/relational/RelationalNode.java
branches/as7/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java
branches/as7/engine/src/main/java/org/teiid/query/processor/xml/RelationalPlanExecutor.java
branches/as7/engine/src/main/java/org/teiid/query/sql/LanguageObject.java
branches/as7/engine/src/main/java/org/teiid/query/tempdata/GlobalTableStoreImpl.java
branches/as7/engine/src/main/java/org/teiid/query/tempdata/TempTable.java
branches/as7/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
branches/as7/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java
branches/as7/engine/src/main/java/org/teiid/query/util/CommandContext.java
branches/as7/engine/src/main/resources/org/teiid/query/i18n.properties
branches/as7/engine/src/test/java/org/teiid/common/buffer/BufferManagerFactory.java
branches/as7/engine/src/test/java/org/teiid/common/buffer/TestLobManager.java
branches/as7/engine/src/test/java/org/teiid/common/buffer/TestSTree.java
branches/as7/engine/src/test/java/org/teiid/common/buffer/TestTupleBuffer.java
branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStorageManager.java
branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestSizeUtility.java
branches/as7/engine/src/test/java/org/teiid/dqp/internal/process/TestCachedResults.java
branches/as7/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
branches/as7/engine/src/test/java/org/teiid/dqp/service/AutoGenDataService.java
branches/as7/engine/src/test/java/org/teiid/query/function/TestFunction.java
branches/as7/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java
branches/as7/engine/src/test/java/org/teiid/query/function/TestFunctionTree.java
branches/as7/engine/src/test/java/org/teiid/query/function/TestResolvedFunctions.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestAccessPatterns.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestAnsiJoinPushdown.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestBatchedUpdatePlanner.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestExpressionsInGroupBy.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestInlineView.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestJoinOptimization.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestJoinPushdownRestrictions.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestOptionalJoins.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestPartitionedJoinPlanning.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestRuleRaiseNull.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestRuleRemoveSorts.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestSortOptimization.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestStoredProcedurePlanning.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestUnionPlanning.java
branches/as7/engine/src/test/java/org/teiid/query/optimizer/relational/TestAliasGenerator.java
branches/as7/engine/src/test/java/org/teiid/query/processor/FakeDataManager.java
branches/as7/engine/src/test/java/org/teiid/query/processor/FakeDataStore.java
branches/as7/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java
branches/as7/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java
branches/as7/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java
branches/as7/engine/src/test/java/org/teiid/query/processor/TestJoinWithFunction.java
branches/as7/engine/src/test/java/org/teiid/query/processor/TestOptionalJoins.java
branches/as7/engine/src/test/java/org/teiid/query/processor/TestOrderByProcessing.java
branches/as7/engine/src/test/java/org/teiid/query/processor/TestProcedureRelational.java
branches/as7/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
branches/as7/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
branches/as7/engine/src/test/java/org/teiid/query/processor/TestSecurityFunctions.java
branches/as7/engine/src/test/java/org/teiid/query/processor/TestSetProcessing.java
branches/as7/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
branches/as7/engine/src/test/java/org/teiid/query/processor/TestTextTable.java
branches/as7/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java
branches/as7/engine/src/test/java/org/teiid/query/processor/TestWithClauseProcessing.java
branches/as7/engine/src/test/java/org/teiid/query/processor/relational/TestJoinNode.java
branches/as7/engine/src/test/java/org/teiid/query/processor/relational/TestProjectIntoNode.java
branches/as7/engine/src/test/java/org/teiid/query/sql/symbol/TestElementSymbol.java
branches/as7/engine/src/test/resources/text/cdm_dos_win.txt
branches/as7/jboss-integration/pom.xml
branches/as7/metadata/src/main/java/org/teiid/internal/core/index/BlocksIndexInput.java
branches/as7/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java
branches/as7/runtime/src/test/java/org/teiid/dqp/service/buffer/TestLocalBufferService.java
branches/as7/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewReplication.java
branches/as7/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java
branches/as7/test-integration/common/src/test/resources/TestODBCSocketTransport/testPk.expected
branches/as7/test-integration/common/src/test/resources/TestODBCSocketTransport/testPkPrepared.expected
branches/as7/test-integration/common/src/test/resources/TestSystemVirtualModel/testProcedureParams.expected
branches/as7/test-integration/common/src/test/resources/TestSystemVirtualModel/testProcedures.expected
Log:
merge -r 3451:3506 from trunk to as7
Property changes on: branches/as7
___________________________________________________________________
Modified: svn:mergeinfo
- /trunk:3188-3450
+ /trunk:3188-3450,3452-3506
Property changes on: branches/as7/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.1.x/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java:2901-2940
/trunk/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java:3188-3450
+ /branches/7.1.x/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java:2901-2940
/trunk/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java:3188-3450,3452-3506
Modified: branches/as7/api/src/main/java/org/teiid/CommandContext.java
===================================================================
--- branches/as7/api/src/main/java/org/teiid/CommandContext.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/api/src/main/java/org/teiid/CommandContext.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -87,7 +87,8 @@
/**
* Get the processor batch size set on the BufferManager
- * @return
+ * @return - the nominal batch size target. actual batch sizes will vary based
+ * upon the column types
*/
int getProcessorBatchSize();
Property changes on: branches/as7/api/src/main/java/org/teiid/events/EventDistributor.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/api/src/main/java/org/teiid/events/EventDistributor.java:3340-3349
/trunk/api/src/main/java/org/teiid/events/EventDistributor.java:3188-3450
+ /branches/7.4.x/api/src/main/java/org/teiid/events/EventDistributor.java:3340-3349
/trunk/api/src/main/java/org/teiid/events/EventDistributor.java:3188-3450,3452-3506
Modified: branches/as7/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml
===================================================================
--- branches/as7/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml 2011-09-29 16:46:38 UTC (rev 3507)
@@ -43,7 +43,11 @@
<!-- Max storage space, in MB, to be used for buffer files (default 50G) -->
<property name="maxBufferSpace">51200</property>
<!-- Max open buffer files (default 64) -->
- <property name="maxOpenFiles">64</property>
+ <property name="maxOpenFiles">64</property>
+ <!-- Set to true to allow inlining of memory based and small lobs into results.
+ However inline lob values are not supported by pre-7.6 clients, so disable this
+ property if using older clients utilizing lobs. (default true) -->
+ <property name="inlineLobs">true</property>
</bean>
<bean name="CacheFactory" class="org.teiid.cache.jboss.ClusterableCacheFactory">
Modified: branches/as7/build/kits/jboss-container/teiid-releasenotes.html
===================================================================
--- branches/as7/build/kits/jboss-container/teiid-releasenotes.html 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/build/kits/jboss-container/teiid-releasenotes.html 2011-09-29 16:46:38 UTC (rev 3507)
@@ -30,6 +30,7 @@
<LI><B>File Enhancements</B> - the file translator can now optionally (via the ExceptionIfFileNotFound property) throw an exception if the path refers to a file that doesn't exist. The file resource adapter can be configured to map file names and can prevent parent path .. references. See the Admin Guide or the file-ds.xml template for more.
<LI><B>TEXTTABLE Enhancements</B> - TEXTTABLE can now parse fixed width files that do not use a row delimiter and can optionally produce fixed values that haven't been trimmed.
<LI><B>Temp table transactions</B> - Internal materialized views and temp table usage from a session and within procedures can take advantage of greater transaction support.
+ <LI><B>Buffering Improvements</B> - Added the ability to inline memory based or small lobs and added tracking of the memory held by soft references.
</UL>
<h2><a name="Compatibility">Compatibility Issues</a></h2>
@@ -39,9 +40,10 @@
<li>Support for using the FROM clause post item hints MAKEDEP/MAKENOTDEP has been deprecated. Use the pre item comment hint syntax instead, e.g. /*+ MAKEDEP */ tbl
</ul>
-<h4>from 7.4</h4>
+<h4>from 7.5</h4>
<ul>
- <li>Leave was added as a reserved word.
+ <li>Leave was added as a reserved word.
+ <li>Lob inlining is incompatible with clients older than 7.6. If a 7.6 server will have older clients that use lobs connect to it, then the BufferService property inlineLobs should be set to false in the teiid-jboss-beans.xml file.
</ul>
<h4>from 7.4</h4>
Modified: branches/as7/client/src/main/java/org/teiid/client/BatchSerializer.java
===================================================================
--- branches/as7/client/src/main/java/org/teiid/client/BatchSerializer.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/client/src/main/java/org/teiid/client/BatchSerializer.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -29,6 +29,7 @@
import java.math.BigInteger;
import java.sql.Time;
import java.sql.Timestamp;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -75,23 +76,23 @@
* @throws IOException
* @since 4.2
*/
- static void writeIsNullData(ObjectOutput out, int col, List[] batch) throws IOException {
- int numBytes = batch.length / 8, row = 0, currentByte = 0;
+ static void writeIsNullData(ObjectOutput out, int col, List<? extends List<?>> batch) throws IOException {
+ int numBytes = batch.size() / 8, row = 0, currentByte = 0;
for (int byteNum = 0; byteNum < numBytes; byteNum++, row+=8) {
- currentByte = (batch[row].get(col) == null) ? 0x80 : 0;
- if (batch[row+1].get(col) == null) currentByte |= 0x40;
- if (batch[row+2].get(col) == null) currentByte |= 0x20;
- if (batch[row+3].get(col) == null) currentByte |= 0x10;
- if (batch[row+4].get(col) == null) currentByte |= 0x08;
- if (batch[row+5].get(col) == null) currentByte |= 0x04;
- if (batch[row+6].get(col) == null) currentByte |= 0x02;
- if (batch[row+7].get(col) == null) currentByte |= 0x01;
+ currentByte = (batch.get(row).get(col) == null) ? 0x80 : 0;
+ if (batch.get(row+1).get(col) == null) currentByte |= 0x40;
+ if (batch.get(row+2).get(col) == null) currentByte |= 0x20;
+ if (batch.get(row+3).get(col) == null) currentByte |= 0x10;
+ if (batch.get(row+4).get(col) == null) currentByte |= 0x08;
+ if (batch.get(row+5).get(col) == null) currentByte |= 0x04;
+ if (batch.get(row+6).get(col) == null) currentByte |= 0x02;
+ if (batch.get(row+7).get(col) == null) currentByte |= 0x01;
out.write(currentByte);
}
- if (batch.length % 8 > 0) {
+ if (batch.size() % 8 > 0) {
currentByte = 0;
- for (int mask = 0x80; row < batch.length; row++, mask >>= 1) {
- if (batch[row].get(col) == null) currentByte |= mask;
+ for (int mask = 0x80; row < batch.size(); row++, mask >>= 1) {
+ if (batch.get(row).get(col) == null) currentByte |= mask;
}
out.write(currentByte);
}
@@ -126,22 +127,22 @@
* @since 4.2
*/
private static class ColumnSerializer {
- public void writeColumn(ObjectOutput out, int col, List[] batch) throws IOException {
+ public void writeColumn(ObjectOutput out, int col, List<? extends List<?>> batch) throws IOException {
writeIsNullData(out, col, batch);
Object obj = null;
- for (int i = 0; i < batch.length; i++) {
- obj = batch[i].get(col);
+ for (int i = 0; i < batch.size(); i++) {
+ obj = batch.get(i).get(col);
if (obj != null) {
writeObject(out, obj);
}
}
}
- public void readColumn(ObjectInput in, int col, List[] batch, byte[] isNull) throws IOException, ClassNotFoundException {
+ public void readColumn(ObjectInput in, int col, List<List<Object>> batch, byte[] isNull) throws IOException, ClassNotFoundException {
readIsNullData(in, isNull);
- for (int i = 0; i < batch.length; i++) {
+ for (int i = 0; i < batch.size(); i++) {
if (!isNullObject(isNull, i)) {
- batch[i].set(col, DataTypeManager.getCanonicalValue(readObject(in)));
+ batch.get(i).set(col, DataTypeManager.getCanonicalValue(readObject(in)));
}
}
}
@@ -203,13 +204,14 @@
/* This implementation compacts the isNull and boolean data for non-null values into a byte[]
* by using a 8 bit mask that is bit-shifted to mask each value.
*/
- public void writeColumn(ObjectOutput out, int col, List[] batch) throws IOException {
+ @Override
+ public void writeColumn(ObjectOutput out, int col, List<? extends List<?>> batch) throws IOException {
int currentByte = 0;
int mask = 0x80;
Object obj;
- for (int row = 0; row < batch.length; row++) {
+ for (int row = 0; row < batch.size(); row++) {
// Write the isNull value
- obj = batch[row].get(col);
+ obj = batch.get(row).get(col);
if (obj == null ) {
currentByte |= mask;
}
@@ -241,10 +243,13 @@
}
}
- public void readColumn(ObjectInput in, int col, List[] batch, byte[] isNull) throws IOException, ClassNotFoundException {
+ @Override
+ public void readColumn(ObjectInput in, int col,
+ List<List<Object>> batch, byte[] isNull) throws IOException,
+ ClassNotFoundException {
int currentByte = 0, mask = 0; // Initialize the mask so that it is reset in the loop
boolean isNullVal;
- for (int row = 0; row < batch.length; row++) {
+ for (int row = 0; row < batch.size(); row++) {
if (mask == 0) {
// If we used up the byte, read the next one, and reset the mask
currentByte = in.read();
@@ -257,7 +262,7 @@
currentByte = in.read();
mask = 0x80;
}
- batch[row].set(col, ((currentByte & mask) == 0) ? Boolean.FALSE : Boolean.TRUE);
+ batch.get(row).set(col, ((currentByte & mask) == 0) ? Boolean.FALSE : Boolean.TRUE);
mask >>= 1;
}
}
@@ -354,17 +359,12 @@
return cs;
}
- public static void writeBatch(ObjectOutput out, String[] types, List[] batch) throws IOException {
- // If there are no type hints, simply use the default mechanism to serialize
- if (types == null || types.length == 0) {
- out.writeObject(batch);
- return;
- }
+ public static void writeBatch(ObjectOutput out, String[] types, List<? extends List<?>> batch) throws IOException {
if (batch == null) {
out.writeInt(-1);
} else {
- out.writeInt(batch.length);
- if (batch.length > 0) {
+ out.writeInt(batch.size());
+ if (batch.size() > 0) {
int columns = types.length;
out.writeInt(columns);
for(int i = 0; i < columns; i++) {
@@ -374,8 +374,8 @@
} catch (ClassCastException e) {
Object obj = null;
String objectClass = null;
- objectSearch: for (int row = 0; row < batch.length; row++) {
- obj = batch[row].get(i);
+ objectSearch: for (int row = 0; row < batch.size(); row++) {
+ obj = batch.get(row).get(i);
if (obj != null) {
objectClass = obj.getClass().getName();
break objectSearch;
@@ -388,21 +388,17 @@
}
}
- public static List[] readBatch(ObjectInput in, String[] types) throws IOException, ClassNotFoundException {
- // If there are no type hints, use the default mechanism to deserialize
- if (types == null || types.length == 0) {
- return (List[])in.readObject();
- }
+ public static List<List<Object>> readBatch(ObjectInput in, String[] types) throws IOException, ClassNotFoundException {
int rows = in.readInt();
if (rows == 0) {
- return new List[0];
+ return new ArrayList<List<Object>>(0);
} else if (rows > 0) {
int columns = in.readInt();
- List[] batch = new List[rows];
+ List<List<Object>> batch = new ArrayList<List<Object>>(rows);
int numBytes = rows/8;
int extraRows = rows % 8;
for (int currentRow = 0; currentRow < rows; currentRow++) {
- batch[currentRow] = Arrays.asList(new Object[columns]);
+ batch.add(currentRow, Arrays.asList(new Object[columns]));
}
byte[] isNullBuffer = new byte[(extraRows > 0) ? numBytes + 1: numBytes];
for (int col = 0; col < columns; col++) {
Modified: branches/as7/client/src/main/java/org/teiid/client/ResultsMessage.java
===================================================================
--- branches/as7/client/src/main/java/org/teiid/client/ResultsMessage.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/client/src/main/java/org/teiid/client/ResultsMessage.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -26,7 +26,7 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
-import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -45,9 +45,9 @@
static final long serialVersionUID = 3546924172976187793L;
- private List[] results = null;
- private String[] columnNames = null;
- private String[] dataTypes = null;
+ private List<? extends List<?>> results;
+ private String[] columnNames;
+ private String[] dataTypes;
/** A description of planning that occurred as requested in the request. */
private PlanNode planDescription;
@@ -85,36 +85,29 @@
public ResultsMessage(){
}
- /**
- * Instantiate and copy relevant information from the original request message.
- * Typically, the transaction context should only be copied if this results
- * message is being returned from the connector to the query engine. Clients
- * will be unable to deserialize this object.
- * @param requestMsg
- * @param copyTransactionContext true if the transaction context should be copied; false otherwise.
- * @since 4.2
- */
- public ResultsMessage(RequestMessage requestMsg){
- this.results = new ArrayList[0];
-
- }
-
- public ResultsMessage(RequestMessage requestMsg, List[] results, String[] columnNames, String[] dataTypes){
- this (requestMsg);
- setResults( results );
+ public ResultsMessage(List<? extends List<?>> results, String[] columnNames, String[] dataTypes){
+ this.results = results;
setFirstRow( 1 );
- setLastRow( results.length );
+ setLastRow( results.size() );
this.columnNames = columnNames;
this.dataTypes = dataTypes;
}
-
- public List[] getResults() {
+
+ public List<? extends List<?>> getResultsList() {
return results;
}
+
+ /**
+ * @deprecated see {@link #getResultsList()}
+ * @return
+ */
+ public List<?>[] getResults() {
+ return results.toArray(new List[results.size()]);
+ }
- public void setResults(List[] results) {
- this.results = results;
+ public void setResults(List<?>[] results) {
+ this.results = Arrays.asList(results);
}
public String[] getColumnNames() {
@@ -341,7 +334,7 @@
*/
public String toString() {
return new StringBuffer("ResultsMessage rowCount=") //$NON-NLS-1$
- .append(results == null ? 0 : results.length)
+ .append(results == null ? 0 : results.size())
.append(" finalRow=") //$NON-NLS-1$
.append(finalRow)
.toString();
Property changes on: branches/as7/client/src/main/java/org/teiid/jdbc/ConnectionImpl.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/client/src/main/java/org/teiid/jdbc/ConnectionImpl.java:3149-3217
/trunk/client/src/main/java/org/teiid/jdbc/ConnectionImpl.java:3188-3450
+ /branches/7.4.x/client/src/main/java/org/teiid/jdbc/ConnectionImpl.java:3149-3217
/trunk/client/src/main/java/org/teiid/jdbc/ConnectionImpl.java:3188-3450,3452-3506
Property changes on: branches/as7/client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java:3281-3325
/trunk/client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java:3188-3450
+ /branches/7.4.x/client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java:3281-3325
/trunk/client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java:3188-3450,3452-3506
Property changes on: branches/as7/client/src/main/java/org/teiid/jdbc/EmbeddedProfile.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/client/src/main/java/org/teiid/jdbc/EmbeddedProfile.java:3149-3217
/trunk/client/src/main/java/org/teiid/jdbc/EmbeddedProfile.java:3188-3450
+ /branches/7.4.x/client/src/main/java/org/teiid/jdbc/EmbeddedProfile.java:3149-3217
/trunk/client/src/main/java/org/teiid/jdbc/EmbeddedProfile.java:3188-3450,3452-3506
Property changes on: branches/as7/client/src/main/java/org/teiid/jdbc/JDBCURL.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/client/src/main/java/org/teiid/jdbc/JDBCURL.java:3149-3217,3281-3325
/trunk/client/src/main/java/org/teiid/jdbc/JDBCURL.java:3188-3450
+ /branches/7.4.x/client/src/main/java/org/teiid/jdbc/JDBCURL.java:3149-3217,3281-3325
/trunk/client/src/main/java/org/teiid/jdbc/JDBCURL.java:3188-3450,3452-3506
Modified: branches/as7/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java
===================================================================
--- branches/as7/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -416,7 +416,7 @@
private Batch getCurrentBatch(ResultsMessage currentResultMsg) {
this.updatedPlanDescription = currentResultMsg.getPlanDescription();
- boolean isLast = currentResultMsg.getResults().length == 0 || currentResultMsg.getFinalRow() == currentResultMsg.getLastRow();
+ boolean isLast = currentResultMsg.getResultsList().size() == 0 || currentResultMsg.getFinalRow() == currentResultMsg.getLastRow();
Batch result = new Batch(currentResultMsg.getResults(), currentResultMsg.getFirstRow(), currentResultMsg.getLastRow(), isLast);
result.setLastRow(currentResultMsg.getFinalRow());
return result;
Property changes on: branches/as7/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java:3281-3325
/trunk/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java:3188-3450
+ /branches/7.4.x/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java:3281-3325
/trunk/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java:3188-3450,3452-3506
Property changes on: branches/as7/client/src/main/java/org/teiid/jdbc/SQLStates.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/client/src/main/java/org/teiid/jdbc/SQLStates.java:3220-3275
/trunk/client/src/main/java/org/teiid/jdbc/SQLStates.java:3188-3450
+ /branches/7.4.x/client/src/main/java/org/teiid/jdbc/SQLStates.java:3220-3275
/trunk/client/src/main/java/org/teiid/jdbc/SQLStates.java:3188-3450,3452-3506
Property changes on: branches/as7/client/src/main/java/org/teiid/jdbc/StatementImpl.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java:3149-3217,3220-3275,3281-3325,3355-3365
/trunk/client/src/main/java/org/teiid/jdbc/StatementImpl.java:3188-3450
+ /branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java:3149-3217,3220-3275,3281-3325,3355-3365
/trunk/client/src/main/java/org/teiid/jdbc/StatementImpl.java:3188-3450,3452-3506
Property changes on: branches/as7/client/src/main/java/org/teiid/jdbc/TeiidSQLException.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/client/src/main/java/org/teiid/jdbc/TeiidSQLException.java:3220-3275
/trunk/client/src/main/java/org/teiid/jdbc/TeiidSQLException.java:3188-3450
+ /branches/7.4.x/client/src/main/java/org/teiid/jdbc/TeiidSQLException.java:3220-3275
/trunk/client/src/main/java/org/teiid/jdbc/TeiidSQLException.java:3188-3450,3452-3506
Property changes on: branches/as7/client/src/main/java/org/teiid/net/socket/SocketServerConnectionFactory.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/client/src/main/java/org/teiid/net/socket/SocketServerConnectionFactory.java:3149-3217
/trunk/client/src/main/java/org/teiid/net/socket/SocketServerConnectionFactory.java:3188-3450
+ /branches/7.4.x/client/src/main/java/org/teiid/net/socket/SocketServerConnectionFactory.java:3149-3217
/trunk/client/src/main/java/org/teiid/net/socket/SocketServerConnectionFactory.java:3188-3450,3452-3506
Modified: branches/as7/client/src/test/java/org/teiid/client/TestBatchSerializer.java
===================================================================
--- branches/as7/client/src/test/java/org/teiid/client/TestBatchSerializer.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/client/src/test/java/org/teiid/client/TestBatchSerializer.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -35,10 +35,10 @@
import java.util.Arrays;
import java.util.List;
-import org.teiid.client.BatchSerializer;
+import junit.framework.TestCase;
+
import org.teiid.core.types.DataTypeManager;
-import junit.framework.TestCase;
@@ -63,21 +63,22 @@
}
}
- private static void helpTestSerialization(String[] types, List[] batch) throws IOException, ClassNotFoundException {
+ private static void helpTestSerialization(String[] types, List<?>[] batch) throws IOException, ClassNotFoundException {
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(byteStream);
- BatchSerializer.writeBatch(out, types, batch);
+ List<List<?>> batchList = Arrays.asList(batch);
+ BatchSerializer.writeBatch(out, types, batchList);
out.flush();
byte[] bytes = byteStream.toByteArray();
ByteArrayInputStream bytesIn = new ByteArrayInputStream(bytes);
ObjectInputStream in = new ObjectInputStream(bytesIn);
- List[] newBatch = BatchSerializer.readBatch(in, types);
+ List<List<Object>> newBatch = BatchSerializer.readBatch(in, types);
out.close();
in.close();
- assertEqual(batch, newBatch);
+ assertTrue(batchList.equals(newBatch));
}
private static final String[] sampleBatchTypes = {DataTypeManager.DefaultDataTypes.BIG_DECIMAL,
@@ -164,14 +165,6 @@
helpTestSerialization(sampleBatchTypes, sampleBatch(833)); // A bunch of rows. This should also test large strings
}
- public void testSerializeBasicTypes_NoTypeHints() throws Exception {
- helpTestSerialization(null, sampleBatch(1));
- helpTestSerialization(null, sampleBatch(8));
- helpTestSerialization(null, sampleBatch(17));
- helpTestSerialization(null, sampleBatch(120));
- helpTestSerialization(null, sampleBatch(833));
- }
-
public void testSerializeBasicTypesWithNulls() throws Exception {
helpTestSerialization(sampleBatchTypes, sampleBatchWithNulls(1));
helpTestSerialization(sampleBatchTypes, sampleBatchWithNulls(8));
@@ -186,10 +179,7 @@
}
public void testSerializeNoData() throws Exception {
- helpTestSerialization(sampleBatchTypes, null);
- helpTestSerialization(null, null);
helpTestSerialization(sampleBatchTypes, new List[0]);
- helpTestSerialization(null, new List[0]);
}
public void testSerializeDatatypeMismatch() throws Exception {
Modified: branches/as7/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java
===================================================================
--- branches/as7/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -797,7 +797,7 @@
private ResultsMessage exampleMessage(List<Object>[] results, String[] columnNames, String[] datatypes) {
RequestMessage request = new RequestMessage();
request.setExecutionId(REQUEST_ID);
- ResultsMessage resultsMsg = new ResultsMessage(request);
+ ResultsMessage resultsMsg = new ResultsMessage();
resultsMsg.setResults(results);
resultsMsg.setColumnNames(columnNames);
resultsMsg.setDataTypes(datatypes);
@@ -834,7 +834,7 @@
private static ResultsMessage exampleResultsMsg4(int begin, int length, boolean lastBatch) {
RequestMessage request = new RequestMessage();
request.setExecutionId(REQUEST_ID);
- ResultsMessage resultsMsg = new ResultsMessage(request);
+ ResultsMessage resultsMsg = new ResultsMessage();
List[] results = exampleResults1(length, begin);
resultsMsg.setResults(results);
resultsMsg.setColumnNames(new String[] { "IntKey" }); //$NON-NLS-1$
@@ -862,7 +862,7 @@
@Test public void testDateType() throws SQLException {
RequestMessage request = new RequestMessage();
request.setExecutionId(REQUEST_ID);
- ResultsMessage resultsMsg = new ResultsMessage(request);
+ ResultsMessage resultsMsg = new ResultsMessage();
resultsMsg.setResults(new List[] {Arrays.asList(new Timestamp(0))});
resultsMsg.setColumnNames(new String[] { "TS" }); //$NON-NLS-1$
resultsMsg.setDataTypes(new String[] { JDBCSQLTypeInfo.TIMESTAMP });
Modified: branches/as7/client/src/test/java/org/teiid/jdbc/TestCallableStatement.java
===================================================================
--- branches/as7/client/src/test/java/org/teiid/jdbc/TestCallableStatement.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/client/src/test/java/org/teiid/jdbc/TestCallableStatement.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -38,9 +38,6 @@
import org.teiid.client.metadata.ParameterInfo;
import org.teiid.client.security.LogonResult;
import org.teiid.core.types.JDBCSQLTypeInfo;
-import org.teiid.jdbc.CallableStatementImpl;
-import org.teiid.jdbc.ConnectionImpl;
-import org.teiid.jdbc.ResultSetImpl;
import org.teiid.net.ServerConnection;
@@ -68,7 +65,7 @@
RequestMessage request = new RequestMessage();
request.setExecutionId(1);
- ResultsMessage resultsMsg = new ResultsMessage(request);
+ ResultsMessage resultsMsg = new ResultsMessage();
List[] results = new List[] {Arrays.asList(null, null, null), Arrays.asList(null, 1, 2)};
resultsMsg.setResults(results);
resultsMsg.setColumnNames(new String[] { "IntNum", "Out1", "Out2" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Property changes on: branches/as7/client/src/test/java/org/teiid/jdbc/TestConnection.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestConnection.java:3281-3325
/trunk/client/src/test/java/org/teiid/jdbc/TestConnection.java:3188-3450
+ /branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestConnection.java:3281-3325
/trunk/client/src/test/java/org/teiid/jdbc/TestConnection.java:3188-3450,3452-3506
Property changes on: branches/as7/client/src/test/java/org/teiid/jdbc/TestSQLException.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestSQLException.java:3220-3275
/trunk/client/src/test/java/org/teiid/jdbc/TestSQLException.java:3188-3450
+ /branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestSQLException.java:3220-3275
/trunk/client/src/test/java/org/teiid/jdbc/TestSQLException.java:3188-3450,3452-3506
Property changes on: branches/as7/client/src/test/java/org/teiid/jdbc/TestStatement.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestStatement.java:3149-3217,3220-3275
/trunk/client/src/test/java/org/teiid/jdbc/TestStatement.java:3188-3450
+ /branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestStatement.java:3149-3217,3220-3275
/trunk/client/src/test/java/org/teiid/jdbc/TestStatement.java:3188-3450,3452-3506
Property changes on: branches/as7/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java:3149-3217,3281-3325
/trunk/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java:3188-3450
+ /branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java:3149-3217,3281-3325
/trunk/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java:3188-3450,3452-3506
Property changes on: branches/as7/common-core/src/main/java/org/teiid/core/TeiidException.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/common-core/src/main/java/org/teiid/core/TeiidException.java:3220-3275
/trunk/common-core/src/main/java/org/teiid/core/TeiidException.java:3188-3450
+ /branches/7.4.x/common-core/src/main/java/org/teiid/core/TeiidException.java:3220-3275
/trunk/common-core/src/main/java/org/teiid/core/TeiidException.java:3188-3450,3452-3506
Property changes on: branches/as7/common-core/src/main/java/org/teiid/core/TeiidRuntimeException.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/common-core/src/main/java/org/teiid/core/TeiidRuntimeException.java:3220-3275
/trunk/common-core/src/main/java/org/teiid/core/TeiidRuntimeException.java:3188-3450
+ /branches/7.4.x/common-core/src/main/java/org/teiid/core/TeiidRuntimeException.java:3220-3275
/trunk/common-core/src/main/java/org/teiid/core/TeiidRuntimeException.java:3188-3450,3452-3506
Modified: branches/as7/common-core/src/main/java/org/teiid/core/types/BaseLob.java
===================================================================
--- branches/as7/common-core/src/main/java/org/teiid/core/types/BaseLob.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/common-core/src/main/java/org/teiid/core/types/BaseLob.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -22,6 +22,7 @@
package org.teiid.core.types;
+import java.io.BufferedInputStream;
import java.io.Externalizable;
import java.io.IOException;
import java.io.InputStream;
@@ -75,17 +76,8 @@
this.charset = charset;
}
- public void free() throws SQLException {
- if (this.streamFactory != null) {
- try {
- this.streamFactory.free();
- this.streamFactory = null;
- } catch (IOException e) {
- SQLException ex = new SQLException(e.getMessage());
- ex.initCause(e);
- throw ex;
- }
- }
+ public void free() {
+ this.streamFactory = null;
}
public Reader getCharacterStream() throws SQLException {
@@ -126,5 +118,35 @@
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(streamFactory);
}
+
+ /**
+ * Returns the number of bytes.
+ */
+ public long length() throws SQLException{
+ if (getStreamFactory().getLength() == -1) {
+ getStreamFactory().setLength(length(getBinaryStream()));
+ }
+ return getStreamFactory().getLength();
+ }
+ static long length(InputStream is) throws SQLException {
+ if (!(is instanceof BufferedInputStream)) {
+ is = new BufferedInputStream(is);
+ }
+ try {
+ long length = 0;
+ while (is.read() != -1) {
+ length++;
+ }
+ return length;
+ } catch (IOException e) {
+ throw new SQLException(e);
+ } finally {
+ try {
+ is.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+
}
Modified: branches/as7/common-core/src/main/java/org/teiid/core/types/BlobImpl.java
===================================================================
--- branches/as7/common-core/src/main/java/org/teiid/core/types/BlobImpl.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/common-core/src/main/java/org/teiid/core/types/BlobImpl.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -22,7 +22,6 @@
package org.teiid.core.types;
-import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -109,32 +108,6 @@
}
/**
- * Returns the number of bytes in the <code>BLOB</code> value
- * designated by this <code>Blob</code> object.
- * @return length of the <code>BLOB</code> in bytes
- */
- public long length() throws SQLException{
- if (getStreamFactory().getLength() == -1) {
- InputStream is = new BufferedInputStream(getBinaryStream());
- try {
- long length = 0;
- while (is.read() != -1) {
- length++;
- }
- getStreamFactory().setLength(length);
- } catch (IOException e) {
- throw new SQLException(e);
- } finally {
- try {
- is.close();
- } catch (IOException e) {
- }
- }
- }
- return getStreamFactory().getLength();
- }
-
- /**
* Determines the byte position in the <code>BLOB</code> value
* designated by this <code>Blob</code> object at which
* <code>pattern</code> begins. The search begins at position
Modified: branches/as7/common-core/src/main/java/org/teiid/core/types/BlobType.java
===================================================================
--- branches/as7/common-core/src/main/java/org/teiid/core/types/BlobType.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/common-core/src/main/java/org/teiid/core/types/BlobType.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -24,6 +24,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.OutputStream;
import java.sql.Blob;
@@ -32,6 +33,7 @@
import javax.sql.rowset.serial.SerialBlob;
import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.util.ObjectConverterUtil;
/**
@@ -61,18 +63,10 @@
public byte[] getBytes(long pos, int length) throws SQLException {
return this.reference.getBytes(pos, length);
}
-
- /**
- * @see java.sql.Blob#length()
- */
- public long length() throws SQLException {
- //caching the length
- if (this.length != -1) {
- return this.length;
- }
- // if did not find before then do it again.
- this.length = this.reference.length();
- return length;
+
+ @Override
+ long computeLength() throws SQLException {
+ return this.reference.length();
}
/**
@@ -142,12 +136,38 @@
}
@Override
- public void writeExternal(ObjectOutput out) throws IOException {
+ protected void readReference(ObjectInput in) throws IOException {
+ byte[] bytes = new byte[(int)getLength()];
+ in.readFully(bytes);
try {
- length();
+ this.reference = new SerialBlob(bytes);
} catch (SQLException e) {
+ throw new IOException(e);
}
- super.writeExternal(out);
}
+ @Override
+ protected void writeReference(final ObjectOutput out) throws IOException {
+ try {
+ writeBinary(out, getBinaryStream(), (int)length);
+ } catch (SQLException e) {
+ throw new IOException();
+ }
+ }
+
+ static void writeBinary(final ObjectOutput out, InputStream is, int length) throws IOException {
+ OutputStream os = new OutputStream() {
+
+ @Override
+ public void write(int b) throws IOException {
+ out.write(b);
+ }
+ };
+ try {
+ ObjectConverterUtil.write(os, is, length, false);
+ } finally {
+ is.close();
+ }
+ }
+
}
Modified: branches/as7/common-core/src/main/java/org/teiid/core/types/ClobType.java
===================================================================
--- branches/as7/common-core/src/main/java/org/teiid/core/types/ClobType.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/common-core/src/main/java/org/teiid/core/types/ClobType.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -24,6 +24,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.OutputStream;
import java.io.Reader;
@@ -35,6 +36,7 @@
import javax.sql.rowset.serial.SerialClob;
import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.util.ObjectConverterUtil;
/**
@@ -72,17 +74,10 @@
public String getSubString(long pos, int length) throws SQLException {
return this.reference.getSubString(pos, length);
}
-
- /**
- * @see java.sql.Clob#length()
- */
- public long length() throws SQLException {
- if (this.length != -1) {
- return this.length;
- }
-
- this.length = this.reference.length();
- return length;
+
+ @Override
+ long computeLength() throws SQLException {
+ return this.reference.length();
}
/**
@@ -218,12 +213,52 @@
}
@Override
- public void writeExternal(ObjectOutput out) throws IOException {
+ protected void readReference(ObjectInput in) throws IOException {
+ char[] chars = new char[(int)length];
+ for (int i = 0; i < chars.length; i++) {
+ chars[i] = in.readChar();
+ }
try {
- length();
+ this.reference = new SerialClob(chars);
} catch (SQLException e) {
+ throw new IOException(e);
}
- super.writeExternal(out);
}
+
+ /**
+ * Since we have the length in chars we'll just write out in double byte format.
+ * These clobs should be small, so the wasted space should be minimal.
+ */
+ @Override
+ protected void writeReference(final ObjectOutput out) throws IOException {
+ Writer w = new Writer() {
+
+ @Override
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ for (int i = off; i < len; i++) {
+ out.writeShort(cbuf[i]);
+ }
+ }
+
+ @Override
+ public void flush() throws IOException {
+ }
+
+ @Override
+ public void close() throws IOException {
+ }
+ };
+ Reader r;
+ try {
+ r = getCharacterStream();
+ } catch (SQLException e) {
+ throw new IOException(e);
+ }
+ try {
+ ObjectConverterUtil.write(w, r, (int)length, false);
+ } finally {
+ r.close();
+ }
+ }
}
Modified: branches/as7/common-core/src/main/java/org/teiid/core/types/DataTypeManager.java
===================================================================
--- branches/as7/common-core/src/main/java/org/teiid/core/types/DataTypeManager.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/common-core/src/main/java/org/teiid/core/types/DataTypeManager.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -126,23 +126,40 @@
}
}
- private static Map<Class<?>, ValueCache<?>> valueMaps = new HashMap<Class<?>, ValueCache<?>>(128);
- private static HashedValueCache<String> stringCache = new HashedValueCache<String>(17) {
+ public static class WeakReferenceHashedValueCache<T> extends HashedValueCache<T> {
+ public WeakReferenceHashedValueCache(int size) {
+ super(size);
+ }
+
+ public T getByHash(Object obj) {
+ int index = hash(obj.hashCode()) & (cache.length - 1);
+ return get(index);
+ }
+
@Override
- protected Object get(int index) {
- WeakReference<?> ref = (WeakReference<?>) cache[index];
+ protected T get(int index) {
+ WeakReference<T> ref = (WeakReference<T>) cache[index];
if (ref != null) {
- return ref.get();
+ T result = ref.get();
+ if (result == null) {
+ cache[index] = null;
+ }
+ return result;
}
return null;
}
@Override
- protected void set(int index, String value) {
- cache[index] = new WeakReference<Object>(value);
- }
+ protected void set(int index, T value) {
+ cache[index] = new WeakReference<T>(value);
+ }
+ }
+
+ private static Map<Class<?>, ValueCache<?>> valueMaps = new HashMap<Class<?>, ValueCache<?>>(128);
+ private static HashedValueCache<String> stringCache = new WeakReferenceHashedValueCache<String>(17) {
+
@Override
protected int primaryHash(String value) {
if (value.length() < 14) {
@@ -536,21 +553,7 @@
valueMaps.put(DefaultDataClasses.DATE, new HashedValueCache<Date>(14));
valueMaps.put(DefaultDataClasses.TIME, new HashedValueCache<Time>(14));
valueMaps.put(DefaultDataClasses.TIMESTAMP, new HashedValueCache<Timestamp>(14));
- valueMaps.put(DefaultDataClasses.BIG_DECIMAL, new HashedValueCache<BigDecimal>(16) {
- @Override
- protected Object get(int index) {
- WeakReference<?> ref = (WeakReference<?>) cache[index];
- if (ref != null) {
- return ref.get();
- }
- return null;
- }
-
- @Override
- protected void set(int index, BigDecimal value) {
- cache[index] = new WeakReference<BigDecimal>(value);
- }
- });
+ valueMaps.put(DefaultDataClasses.BIG_DECIMAL, new WeakReferenceHashedValueCache<BigDecimal>(16));
valueMaps.put(DefaultDataClasses.STRING, stringCache);
}
}
Modified: branches/as7/common-core/src/main/java/org/teiid/core/types/InputStreamFactory.java
===================================================================
--- branches/as7/common-core/src/main/java/org/teiid/core/types/InputStreamFactory.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/common-core/src/main/java/org/teiid/core/types/InputStreamFactory.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -36,12 +36,21 @@
import java.sql.SQLXML;
import javax.activation.DataSource;
+import javax.sql.rowset.serial.SerialBlob;
+import javax.sql.rowset.serial.SerialClob;
import javax.xml.transform.Source;
import org.teiid.core.util.ReaderInputStream;
public abstract class InputStreamFactory implements Source {
+ public enum StorageMode {
+ MEMORY, //TODO: sources may return Serial values that are much too large and we should convert them to persistent.
+ PERSISTENT,
+ FREE,
+ OTHER
+ }
+
public interface StreamFactoryReference {
void setStreamFactory(InputStreamFactory inputStreamFactory);
@@ -49,7 +58,7 @@
}
private String systemId;
- private long length = -1;
+ protected long length = -1;
/**
* Get a new InputStream
@@ -67,10 +76,17 @@
this.systemId = systemId;
}
+ /**
+ * @throws IOException
+ */
public void free() throws IOException {
}
+ /**
+ * Length in bytes of the {@link InputStream}
+ * @return the length or -1 if the length is not known
+ */
public long getLength() {
return length;
}
@@ -79,12 +95,15 @@
this.length = length;
}
+ /**
+ * @throws IOException
+ */
public Reader getCharacterStream() throws IOException {
return null;
}
- public boolean isPersistent() {
- return false;
+ public StorageMode getStorageMode() {
+ return StorageMode.OTHER;
}
public static class FileInputStreamFactory extends InputStreamFactory {
@@ -107,8 +126,8 @@
}
@Override
- public boolean isPersistent() {
- return true;
+ public StorageMode getStorageMode() {
+ return StorageMode.PERSISTENT;
}
}
@@ -162,6 +181,11 @@
public OutputStream getOutputStream() throws IOException {
throw new UnsupportedOperationException();
}
+
+ @Override
+ public StorageMode getStorageMode() {
+ return getStorageMode(clob);
+ }
}
@@ -184,11 +208,13 @@
@Override
public long getLength() {
- try {
- return blob.length();
- } catch (SQLException e) {
- return -1;
- }
+ if (length == -1) {
+ try {
+ length = blob.length();
+ } catch (SQLException e) {
+ }
+ }
+ return length;
}
@Override
@@ -205,9 +231,35 @@
public OutputStream getOutputStream() throws IOException {
throw new UnsupportedOperationException();
}
+
+ @Override
+ public StorageMode getStorageMode() {
+ return getStorageMode(blob);
+ }
}
+ public static StorageMode getStorageMode(Object lob) {
+ if (lob instanceof Streamable<?>) {
+ return getStorageMode(((Streamable<?>)lob).getReference());
+ }
+ if (lob instanceof SerialClob) {
+ return StorageMode.MEMORY;
+ }
+ if (lob instanceof SerialBlob) {
+ return StorageMode.MEMORY;
+ }
+ if (lob instanceof BaseLob) {
+ BaseLob baseLob = (BaseLob)lob;
+ try {
+ return baseLob.getStreamFactory().getStorageMode();
+ } catch (SQLException e) {
+ return StorageMode.FREE;
+ }
+ }
+ return StorageMode.OTHER;
+ }
+
public static class SQLXMLInputStreamFactory extends InputStreamFactory implements DataSource {
private SQLXML sqlxml;
@@ -248,6 +300,11 @@
public OutputStream getOutputStream() throws IOException {
throw new UnsupportedOperationException();
}
+
+ @Override
+ public StorageMode getStorageMode() {
+ return getStorageMode(sqlxml);
+ }
}
Modified: branches/as7/common-core/src/main/java/org/teiid/core/types/SQLXMLImpl.java
===================================================================
--- branches/as7/common-core/src/main/java/org/teiid/core/types/SQLXMLImpl.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/common-core/src/main/java/org/teiid/core/types/SQLXMLImpl.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -71,6 +71,16 @@
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(bytes);
}
+
+ @Override
+ public StorageMode getStorageMode() {
+ return StorageMode.MEMORY;
+ }
+
+ @Override
+ public long getLength() {
+ return bytes.length;
+ }
});
setEncoding(Streamable.ENCODING);
}
Modified: branches/as7/common-core/src/main/java/org/teiid/core/types/Streamable.java
===================================================================
--- branches/as7/common-core/src/main/java/org/teiid/core/types/Streamable.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/common-core/src/main/java/org/teiid/core/types/Streamable.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -27,7 +27,8 @@
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.nio.charset.Charset;
-import java.util.concurrent.atomic.AtomicInteger;
+import java.sql.SQLException;
+import java.util.concurrent.atomic.AtomicLong;
import org.teiid.core.CorePlugin;
@@ -44,7 +45,7 @@
private static final long serialVersionUID = -8252488562134729374L;
- private static AtomicInteger counter = new AtomicInteger();
+ private static AtomicLong counter = new AtomicLong();
public static final String ENCODING = "UTF-8"; //$NON-NLS-1$
public static final Charset CHARSET = Charset.forName(ENCODING);
@@ -66,10 +67,23 @@
this.reference = reference;
}
+ /**
+ * Returns the cached length. May be binary or character based.
+ * @return
+ */
public long getLength() {
return length;
}
+ abstract long computeLength() throws SQLException;
+
+ public long length() throws SQLException {
+ if (length == -1) {
+ length = computeLength();
+ }
+ return length;
+ }
+
public T getReference() {
return reference;
}
@@ -82,9 +96,9 @@
return this.referenceStreamId;
}
- /*public void setReferenceStreamId(String id) {
+ public void setReferenceStreamId(String id) {
this.referenceStreamId = id;
- }*/
+ }
@Override
public String toString() {
@@ -99,12 +113,27 @@
ClassNotFoundException {
length = in.readLong();
referenceStreamId = (String)in.readObject();
+ if (referenceStreamId == null) {
+ //we expect the data inline
+ readReference(in);
+ }
}
+ protected abstract void readReference(ObjectInput in) throws IOException;
+
@Override
public void writeExternal(ObjectOutput out) throws IOException {
+ try {
+ length();
+ } catch (SQLException e) {
+ }
out.writeLong(length);
out.writeObject(referenceStreamId);
+ if (referenceStreamId == null) {
+ writeReference(out);
+ }
}
-
+
+ protected abstract void writeReference(ObjectOutput out) throws IOException;
+
}
Modified: branches/as7/common-core/src/main/java/org/teiid/core/types/XMLType.java
===================================================================
--- branches/as7/common-core/src/main/java/org/teiid/core/types/XMLType.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/common-core/src/main/java/org/teiid/core/types/XMLType.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -189,4 +189,29 @@
}
}
}
+
+ @Override
+ long computeLength() throws SQLException {
+ if (this.reference instanceof SQLXMLImpl) {
+ SQLXMLImpl impl = (SQLXMLImpl)this.reference;
+ return impl.length();
+ }
+ return BaseLob.length(getBinaryStream());
+ }
+
+ @Override
+ protected void readReference(ObjectInput in) throws IOException {
+ byte[] bytes = new byte[(int)getLength()];
+ in.readFully(bytes);
+ this.reference = new SQLXMLImpl(bytes);
+ }
+
+ @Override
+ protected void writeReference(final ObjectOutput out) throws IOException {
+ try {
+ BlobType.writeBinary(out, getBinaryStream(), (int)length);
+ } catch (SQLException e) {
+ throw new IOException();
+ }
+ }
}
Modified: branches/as7/common-core/src/main/resources/org/teiid/core/util/application.properties
===================================================================
--- branches/as7/common-core/src/main/resources/org/teiid/core/util/application.properties 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/common-core/src/main/resources/org/teiid/core/util/application.properties 2011-09-29 16:46:38 UTC (rev 3507)
@@ -1,5 +1,5 @@
-build.releaseNumber=${pom.version}
-build.number=${pom.version}
+build.releaseNumber=${project.version}
+build.number=${project.version}
build.date=@build-date@
copyright=Copyright (C) 2008-2009 Red Hat, Inc
url=${site.url}
\ No newline at end of file
Property changes on: branches/as7/common-core/src/test/java/org/teiid/core/TestMetaMatrixRuntimeException.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/common-core/src/test/java/org/teiid/core/TestMetaMatrixRuntimeException.java:3220-3275
/trunk/common-core/src/test/java/org/teiid/core/TestMetaMatrixRuntimeException.java:3188-3450
+ /branches/7.4.x/common-core/src/test/java/org/teiid/core/TestMetaMatrixRuntimeException.java:3220-3275
/trunk/common-core/src/test/java/org/teiid/core/TestMetaMatrixRuntimeException.java:3188-3450,3452-3506
Modified: branches/as7/common-core/src/test/java/org/teiid/core/types/TestBlobValue.java
===================================================================
--- branches/as7/common-core/src/test/java/org/teiid/core/types/TestBlobValue.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/common-core/src/test/java/org/teiid/core/types/TestBlobValue.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -22,21 +22,14 @@
package org.teiid.core.types;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
import javax.sql.rowset.serial.SerialBlob;
-import org.teiid.core.types.BlobType;
-import org.teiid.core.util.UnitTestUtil;
-
-
import junit.framework.TestCase;
+import org.junit.Test;
+import org.teiid.core.util.UnitTestUtil;
+
public class TestBlobValue extends TestCase {
public void testBlobValue() throws Exception {
@@ -55,22 +48,27 @@
String key = bv.getReferenceStreamId();
// now force to serialize
- File saved = new File(UnitTestUtil.getTestScratchPath()+"/blobassaved.bin"); //$NON-NLS-1$
- ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(saved));
- out.writeObject(bv);
- out.close();
-
- // now read back the object from serilized state
- ObjectInputStream in = new ObjectInputStream(new FileInputStream(saved));
- BlobType read = (BlobType)in.readObject();
+ BlobType read = UnitTestUtil.helpSerialize(bv);
// make sure we have kept the reference stream id
assertEquals(key, read.getReferenceStreamId());
// and lost the original object
assertNull(read.getReference());
+ }
+
+ @Test public void testReferencePersistence() throws Exception {
+ String testString = "this is test clob"; //$NON-NLS-1$
+ SerialBlob blob = new SerialBlob(testString.getBytes());
- saved.delete();
+ BlobType bv = new BlobType(blob);
+ bv.setReferenceStreamId(null);
+ // now force to serialize
+ BlobType read = UnitTestUtil.helpSerialize(bv);
+
+ assertNull(read.getReferenceStreamId());
+
+ assertEquals(testString, new String(read.getBytes(1, (int)blob.length())));
}
}
Modified: branches/as7/common-core/src/test/java/org/teiid/core/types/TestClobValue.java
===================================================================
--- branches/as7/common-core/src/test/java/org/teiid/core/types/TestClobValue.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/common-core/src/test/java/org/teiid/core/types/TestClobValue.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -24,12 +24,7 @@
import static org.junit.Assert.*;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
import java.io.Reader;
import javax.sql.rowset.serial.SerialClob;
@@ -56,15 +51,8 @@
String key = cv.getReferenceStreamId();
// now force to serialize
- File saved = new File(UnitTestUtil.getTestScratchPath()+"/clobassaved.bin"); //$NON-NLS-1$
- ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(saved));
- out.writeObject(cv);
- out.close();
+ ClobType read = UnitTestUtil.helpSerialize(cv);
- // now read back the object from serilized state
- ObjectInputStream in = new ObjectInputStream(new FileInputStream(saved));
- ClobType read = (ClobType)in.readObject();
-
assertTrue(read.length() > 0);
// make sure we have kept the reference stream id
@@ -72,8 +60,21 @@
// and lost the original object
assertNull(read.getReference());
+ }
+
+ @Test public void testReferencePersistence() throws Exception {
+ String testString = "this is test clob"; //$NON-NLS-1$
+ SerialClob clob = new SerialClob(testString.toCharArray());
- saved.delete();
+ ClobType cv = new ClobType(clob);
+ cv.setReferenceStreamId(null);
+
+ // now force to serialize
+ ClobType read = UnitTestUtil.helpSerialize(cv);
+
+ assertTrue(read.length() > 0);
+
+ assertEquals(testString, read.getSubString(1, testString.length()));
}
@Test public void testClobSubstring() throws Exception {
Modified: branches/as7/common-core/src/test/java/org/teiid/core/types/TestXMLValue.java
===================================================================
--- branches/as7/common-core/src/test/java/org/teiid/core/types/TestXMLValue.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/common-core/src/test/java/org/teiid/core/types/TestXMLValue.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -22,20 +22,11 @@
package org.teiid.core.types;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
+import junit.framework.TestCase;
-import org.teiid.core.types.SQLXMLImpl;
-import org.teiid.core.types.XMLType;
import org.teiid.core.util.UnitTestUtil;
-import junit.framework.TestCase;
-
-
public class TestXMLValue extends TestCase {
public void testXMLValue() throws Exception {
@@ -55,22 +46,26 @@
String key = xv.getReferenceStreamId();
// now force to serialize
- File saved = new File(UnitTestUtil.getTestScratchPath()+"/xmlsaved.bin"); //$NON-NLS-1$
- ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(saved));
- out.writeObject(xv);
- out.close();
-
- // now read back the object from serilized state
- ObjectInputStream in = new ObjectInputStream(new FileInputStream(saved));
- XMLType read = (XMLType)in.readObject();
+ XMLType read = UnitTestUtil.helpSerialize(xv);
// make sure we have kept the reference stream id
assertEquals(key, read.getReferenceStreamId());
// and lost the original object
assertNull(read.getReference());
+ }
+
+ public void testReferencePersistence() throws Exception {
+ String testString = "<foo>this is an xml value test</foo>"; //$NON-NLS-1$
+ SQLXMLImpl xml = new SQLXMLImpl(testString);
- saved.delete();
+ XMLType xv = new XMLType(xml);
+ xv.setReferenceStreamId(null);
+
+ // now force to serialize
+ XMLType read = UnitTestUtil.helpSerialize(xv);
+
+ assertEquals(testString, read.getString());
}
}
Modified: branches/as7/common-core/src/test/java/org/teiid/core/util/UnitTestUtil.java
===================================================================
--- branches/as7/common-core/src/test/java/org/teiid/core/util/UnitTestUtil.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/common-core/src/test/java/org/teiid/core/util/UnitTestUtil.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -28,7 +28,16 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.io.PrintWriter;
import java.io.Serializable;
+import java.io.Writer;
+import java.sql.Timestamp;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Formatter;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
@@ -388,6 +397,7 @@
return filePath;
}
+ @SuppressWarnings("unchecked")
public static final <T extends Serializable> T helpSerialize(T object) throws IOException, ClassNotFoundException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
@@ -398,5 +408,59 @@
return (T)ois.readObject();
}
+
+ public static void enableTraceLogging(String loggerName) {
+ Logger logger = Logger.getLogger(loggerName);
+ logger.setLevel(Level.FINEST);
+ if (logger.getHandlers().length > 0) {
+ for (Handler h : logger.getHandlers()) {
+ h.setLevel(Level.FINEST);
+ }
+ } else {
+ logger.setUseParentHandlers(false);
+ ConsoleHandler ch = new ConsoleHandler();
+ ch.setFormatter(new Formatter() {
+
+ @Override
+ public String format(LogRecord record) {
+ final StringBuilder result = new StringBuilder();
+ result.append(new Timestamp(record.getMillis()));
+ result.append(" "); //$NON-NLS-1$
+ result.append(record.getLoggerName());
+ result.append(" "); //$NON-NLS-1$
+ result.append(record.getLevel());
+ result.append(" "); //$NON-NLS-1$
+ result.append(record.getThreadID());
+ result.append(" "); //$NON-NLS-1$
+ result.append(record.getMessage());
+ result.append('\n');
+ if (record.getThrown() != null) {
+ record.getThrown().printStackTrace(new PrintWriter(new Writer() {
+ @Override
+ public void close() throws IOException {
+
+ }
+
+ @Override
+ public void flush() throws IOException {
+
+ }
+
+ @Override
+ public void write(char[] cbuf, int off, int len)
+ throws IOException {
+ result.append(new String(cbuf, off, len));
+ }
+ }));
+ result.append('\n');
+ }
+ return result.toString();
+ }
+ });
+ ch.setLevel(Level.FINEST);
+ logger.addHandler(ch);
+ }
+ }
+
}
Modified: branches/as7/documentation/caching-guide/src/main/docbook/en-US/content/hint-option.xml
===================================================================
--- branches/as7/documentation/caching-guide/src/main/docbook/en-US/content/hint-option.xml 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/documentation/caching-guide/src/main/docbook/en-US/content/hint-option.xml 2011-09-29 16:46:38 UTC (rev 3507)
@@ -19,6 +19,9 @@
<itemizedlist>
<listitem><para>The cache hint should appear at the beginning of the SQL. It will not have any affect on INSERT/UPDATE/DELETE statements or virtual update procedure definitions.</para></listitem>
<listitem><para><emphasis>pref_mem</emphasis> - if present indicates that the cached results should prefer to remain in memory. They are not however required to be memory only.
+ <note><para>Care should be taken to not over use the pref_mem option.
+ The memory preference is implemented with Java soft references. While soft references are effective at preventing out of memory conditions.
+ Too much memory held by soft references can limit the effective working memory. Consult your JVM options for clearing soft references if you need to tune their behavior.</para></note>
</para></listitem>
<listitem><para><emphasis>ttl:n</emphasis> - if present n indicates the time to live value in milliseconds.
</para></listitem>
Copied: branches/as7/engine/src/main/java/org/teiid/common/buffer/AutoCleanupUtil.java (from rev 3506, trunk/engine/src/main/java/org/teiid/common/buffer/AutoCleanupUtil.java)
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/AutoCleanupUtil.java (rev 0)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/AutoCleanupUtil.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.common.buffer;
+
+import java.lang.ref.PhantomReference;
+import java.lang.ref.ReferenceQueue;
+import java.util.Collections;
+import java.util.IdentityHashMap;
+import java.util.Set;
+
+public class AutoCleanupUtil {
+
+ public interface Removable {
+ public void remove();
+ }
+
+ static final class PhantomCleanupReference extends PhantomReference<Object> {
+
+ private Removable removable;
+
+ public PhantomCleanupReference(Object referent, Removable removable) {
+ super(referent, QUEUE);
+ this.removable = removable;
+ }
+
+ public void cleanup() {
+ try {
+ this.removable.remove();
+ } finally {
+ this.removable = null;
+ this.clear();
+ }
+ }
+ }
+
+ private static ReferenceQueue<Object> QUEUE = new ReferenceQueue<Object>();
+ private static final Set<PhantomReference<Object>> REFERENCES = Collections.synchronizedSet(Collections.newSetFromMap(new IdentityHashMap<PhantomReference<Object>, Boolean>()));
+
+ public static void setCleanupReference(Object o, Removable r) {
+ REFERENCES.add(new PhantomCleanupReference(o, r));
+ doCleanup();
+ }
+
+ public static void doCleanup() {
+ for (int i = 0; i < 10; i++) {
+ PhantomCleanupReference ref = (PhantomCleanupReference)QUEUE.poll();
+ if (ref == null) {
+ break;
+ }
+ ref.cleanup();
+ REFERENCES.remove(ref);
+ }
+ }
+}
Modified: branches/as7/engine/src/main/java/org/teiid/common/buffer/BatchManager.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/BatchManager.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/BatchManager.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -22,36 +22,29 @@
package org.teiid.common.buffer;
+import java.lang.ref.Reference;
+import java.util.List;
+
import org.teiid.core.TeiidComponentException;
+/**
+ * Acts as a combination serializer/cachemanager
+ */
public interface BatchManager {
- public interface CleanupHook {
-
- void cleanup();
-
- }
+ List<List<?>> getBatch(Long batch, boolean retain) throws TeiidComponentException;
- public interface ManagedBatch {
-
- TupleBatch getBatch(boolean cache, String[] types) throws TeiidComponentException;
-
- void remove();
-
- void setPrefersMemory(boolean prefers);
-
- /**
- * Get an object that can cleaup the {@link ManagedBatch}, but does not hold a hard reference to
- * the {@link ManagedBatch} or the {@link BatchManager}
- * @return
- */
- CleanupHook getCleanupHook();
-
- }
+ void remove(Long batch);
- ManagedBatch createManagedBatch(TupleBatch batch, boolean softCache) throws TeiidComponentException;
+ void setPrefersMemory(boolean prefers);
+ boolean prefersMemory();
+
+ Long createManagedBatch(List<? extends List<?>> batch) throws TeiidComponentException;
+
void remove();
- FileStore createStorage(String prefix);
+ Reference<? extends BatchManager> getBatchManagerReference();
+
+ String[] getTypes();
}
Property changes on: branches/as7/engine/src/main/java/org/teiid/common/buffer/BlockedException.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/main/java/org/teiid/common/buffer/BlockedException.java:3149-3217
/trunk/engine/src/main/java/org/teiid/common/buffer/BlockedException.java:3188-3450
+ /branches/7.4.x/engine/src/main/java/org/teiid/common/buffer/BlockedException.java:3149-3217
/trunk/engine/src/main/java/org/teiid/common/buffer/BlockedException.java:3188-3450,3452-3506
Modified: branches/as7/engine/src/main/java/org/teiid/common/buffer/BufferManager.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/BufferManager.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/BufferManager.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -75,6 +75,12 @@
* Get the batch size to use during query processing.
* @return Batch size (# of rows)
*/
+ int getProcessorBatchSize(List<? extends Expression> schema);
+
+ /**
+ * Get the nominal batch size target
+ * @return
+ */
int getProcessorBatchSize();
/**
Property changes on: branches/as7/engine/src/main/java/org/teiid/common/buffer/BufferManager.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/main/java/org/teiid/common/buffer/BufferManager.java:3220-3275
/trunk/engine/src/main/java/org/teiid/common/buffer/BufferManager.java:3188-3450
+ /branches/7.4.x/engine/src/main/java/org/teiid/common/buffer/BufferManager.java:3220-3275
/trunk/engine/src/main/java/org/teiid/common/buffer/BufferManager.java:3188-3450,3452-3506
Copied: branches/as7/engine/src/main/java/org/teiid/common/buffer/Cache.java (from rev 3506, trunk/engine/src/main/java/org/teiid/common/buffer/Cache.java)
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/Cache.java (rev 0)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/Cache.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer;
+
+import java.util.Collection;
+
+import org.teiid.core.TeiidComponentException;
+
+/**
+ * Represents the storage strategy for the {@link BufferManager}
+ */
+public interface Cache extends StorageManager {
+ void createCacheGroup(Long gid); //called prior to adding an entry
+ Collection<Long> removeCacheGroup(Long gid);
+ void addToCacheGroup(Long gid, Long oid);
+ CacheEntry get(Long id, Serializer<?> serializer) throws TeiidComponentException;
+ void add(CacheEntry entry, Serializer<?> s);
+ void remove(Long gid, Long id);
+}
\ No newline at end of file
Copied: branches/as7/engine/src/main/java/org/teiid/common/buffer/CacheEntry.java (from rev 3506, trunk/engine/src/main/java/org/teiid/common/buffer/CacheEntry.java)
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/CacheEntry.java (rev 0)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/CacheEntry.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer;
+
+import java.lang.ref.WeakReference;
+
+public class CacheEntry {
+ private boolean persistent;
+ private Object object;
+ private int sizeEstimate;
+ private WeakReference<? extends Serializer<?>> serializer;
+ private Long id;
+
+ public CacheEntry(Long id) {
+ this.id = id;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ @Override
+ public int hashCode() {
+ return getId().hashCode();
+ }
+
+ public int getSizeEstimate() {
+ return sizeEstimate;
+ }
+
+ public void setSizeEstimate(int sizeEstimate) {
+ this.sizeEstimate = sizeEstimate;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof CacheEntry)) {
+ return false;
+ }
+ return getId().equals(((CacheEntry)obj).getId());
+ }
+
+ @Override
+ public String toString() {
+ return getId().toString();
+ }
+
+ public Object nullOut() {
+ Object result = getObject();
+ setObject(null);
+ setSerializer(null);
+ return result;
+ }
+
+ public void setObject(Object object) {
+ this.object = object;
+ }
+
+ public Object getObject() {
+ return object;
+ }
+
+ public void setPersistent(boolean persistent) {
+ this.persistent = persistent;
+ }
+
+ public boolean isPersistent() {
+ return persistent;
+ }
+
+ public void setSerializer(WeakReference<? extends Serializer<?>> serializer) {
+ this.serializer = serializer;
+ }
+
+ public WeakReference<? extends Serializer<?>> getSerializer() {
+ return serializer;
+ }
+
+}
\ No newline at end of file
Modified: branches/as7/engine/src/main/java/org/teiid/common/buffer/FileStore.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/FileStore.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/FileStore.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -25,20 +25,14 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.lang.ref.PhantomReference;
-import java.lang.ref.ReferenceQueue;
+import java.nio.ByteBuffer;
import java.util.Arrays;
-import java.util.Collections;
-import java.util.IdentityHashMap;
-import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
-import org.teiid.core.TeiidComponentException;
+import org.teiid.common.buffer.AutoCleanupUtil.Removable;
-public abstract class FileStore {
-
- private static ReferenceQueue<Object> QUEUE = new ReferenceQueue<Object>();
- private static final Set<PhantomReference<Object>> REFERENCES = Collections.newSetFromMap(new IdentityHashMap<PhantomReference<Object>, Boolean>());
-
+public abstract class FileStore implements Removable {
+
/**
* A customized buffered stream with an exposed buffer
*/
@@ -80,12 +74,8 @@
}
private void writeDirect(byte[] b, int off, int len) throws IOException {
- try {
- FileStore.this.write(b, off, len);
- bytesWritten = true;
- } catch (TeiidComponentException e) {
- throw new IOException(e);
- }
+ FileStore.this.write(b, off, len);
+ bytesWritten = true;
}
public void flushBuffer() throws IOException {
@@ -140,84 +130,59 @@
}
- static class CleanupReference extends PhantomReference<Object> {
-
- private FileStore store;
-
- public CleanupReference(Object referent, FileStore store) {
- super(referent, QUEUE);
- this.store = store;
- }
-
- public void cleanup() {
- try {
- this.store.remove();
- } finally {
- this.clear();
- }
- }
- }
+ private AtomicBoolean removed = new AtomicBoolean();
- private boolean removed;
- protected long len;
+ public abstract long getLength();
- public void setCleanupReference(Object o) {
- REFERENCES.add(new CleanupReference(o, this));
- for (int i = 0; i < 10; i++) {
- CleanupReference ref = (CleanupReference)QUEUE.poll();
- if (ref == null) {
- break;
- }
- ref.cleanup();
- REFERENCES.remove(ref);
- }
- }
+ public abstract void setLength(long length) throws IOException;
- public synchronized long getLength() {
- return len;
- }
-
public int read(long fileOffset, byte[] b, int offSet, int length)
- throws TeiidComponentException {
- if (removed) {
- throw new TeiidComponentException("already removed"); //$NON-NLS-1$
+ throws IOException {
+ checkRemoved();
+ return readWrite(fileOffset, b, offSet, length, false);
+ }
+
+ private void checkRemoved() throws IOException {
+ if (removed.get()) {
+ throw new IOException("already removed"); //$NON-NLS-1$
}
- return readDirect(fileOffset, b, offSet, length);
}
- protected abstract int readDirect(long fileOffset, byte[] b, int offSet, int length)
- throws TeiidComponentException;
+ protected abstract int readWrite(long fileOffset, byte[] b, int offSet, int length, boolean write)
+ throws IOException;
- public void readFully(long fileOffset, byte[] b, int offSet, int length) throws TeiidComponentException {
+ public void readFully(long fileOffset, byte[] b, int offSet, int length) throws IOException {
+ if (length == 0) {
+ return;
+ }
int n = 0;
do {
int count = this.read(fileOffset + n, b, offSet + n, length - n);
- if (count < 0) {
- throw new TeiidComponentException("not enough bytes available"); //$NON-NLS-1$
+ if (count <= 0 && length > 0) {
+ throw new IOException("not enough bytes available"); //$NON-NLS-1$
}
n += count;
} while (n < length);
}
- public void write(byte[] bytes) throws TeiidComponentException {
- write(bytes, 0, bytes.length);
+ public synchronized void write(byte[] bytes, int offset, int length) throws IOException {
+ write(getLength(), bytes, offset, length);
}
-
- public synchronized long write(byte[] bytes, int offset, int length) throws TeiidComponentException {
- if (removed) {
- throw new TeiidComponentException("already removed"); //$NON-NLS-1$
- }
- writeDirect(bytes, offset, length);
- long result = len;
- len += length;
- return result;
+
+ public void write(long start, byte[] bytes, int offset, int length) throws IOException {
+ int n = 0;
+ do {
+ checkRemoved();
+ int count = this.readWrite(start + n, bytes, offset + n, length - n, true);
+ if (count <= 0 && length > 0) {
+ throw new IOException("not enough bytes available"); //$NON-NLS-1$
+ }
+ n += count;
+ } while (n < length);
}
- protected abstract void writeDirect(byte[] bytes, int offset, int length) throws TeiidComponentException;
-
public void remove() {
- if (!this.removed) {
- this.removed = true;
+ if (removed.compareAndSet(false, true)) {
this.removeDirect();
}
}
@@ -241,28 +206,46 @@
@Override
public int read(byte[] b, int off, int len) throws IOException {
- try {
- if (this.streamLength != -1 && len > this.streamLength) {
- len = (int)this.streamLength;
- }
- if (this.streamLength == -1 || this.streamLength > 0) {
- int bytes = FileStore.this.read(offset, b, off, len);
- if (bytes != -1) {
- this.offset += bytes;
- if (this.streamLength != -1) {
- this.streamLength -= bytes;
- }
+ if (this.streamLength != -1 && len > this.streamLength) {
+ len = (int)this.streamLength;
+ }
+ if (this.streamLength == -1 || this.streamLength > 0) {
+ int bytes = FileStore.this.read(offset, b, off, len);
+ if (bytes != -1) {
+ this.offset += bytes;
+ if (this.streamLength != -1) {
+ this.streamLength -= bytes;
}
- return bytes;
}
- return -1;
- } catch (TeiidComponentException e) {
- throw new IOException(e);
+ return bytes;
}
+ return -1;
}
};
}
+ public ByteBuffer getBuffer(long start, int length, boolean allocate) throws IOException {
+ byte[] b = new byte[length];
+ if (!allocate) {
+ readFully(start, b, 0, length);
+ }
+ return ByteBuffer.wrap(b);
+ }
+
+ public void updateFromBuffer(ByteBuffer bb, long start) throws IOException {
+ byte[] b = null;
+ int offset = 0;
+ bb.rewind();
+ if (bb.hasArray()) {
+ b = bb.array();
+ offset = bb.arrayOffset();
+ } else {
+ b = new byte[bb.limit()];
+ bb.get(b);
+ }
+ write(start, b, offset, bb.limit());
+ }
+
public InputStream createInputStream(final long start) {
return createInputStream(start, -1);
}
@@ -277,16 +260,12 @@
@Override
public void write(byte[] b, int off, int len) throws IOException {
- try {
- FileStore.this.write(b, off, len);
- } catch (TeiidComponentException e) {
- throw new IOException(e);
- }
+ FileStore.this.write(b, off, len);
}
};
}
- public FileStoreOutputStream createOutputStream(int maxMemorySize) {
+ public FileStoreOutputStream createOutputStream(int maxMemorySize) {
return new FileStoreOutputStream(maxMemorySize);
}
Modified: branches/as7/engine/src/main/java/org/teiid/common/buffer/FileStoreInputStreamFactory.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/FileStoreInputStreamFactory.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/FileStoreInputStreamFactory.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -42,7 +42,7 @@
public FileStoreInputStreamFactory(FileStore lobBuffer, String encoding) {
this.encoding = encoding;
this.lobBuffer = lobBuffer;
- this.lobBuffer.setCleanupReference(this);
+ AutoCleanupUtil.setCleanupReference(this, lobBuffer);
}
@Override
@@ -56,6 +56,9 @@
@Override
public long getLength() {
+ if (fsos != null && !fsos.bytesWritten()) {
+ return fsos.getCount();
+ }
return lobBuffer.getLength();
}
@@ -86,7 +89,10 @@
}
@Override
- public boolean isPersistent() {
- return fsos == null || fsos.bytesWritten();
+ public StorageMode getStorageMode() {
+ if (fsos == null) {
+ return StorageMode.PERSISTENT;
+ }
+ return StorageMode.MEMORY;
}
}
\ No newline at end of file
Copied: branches/as7/engine/src/main/java/org/teiid/common/buffer/LightWeightCopyOnWriteList.java (from rev 3506, trunk/engine/src/main/java/org/teiid/common/buffer/LightWeightCopyOnWriteList.java)
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/LightWeightCopyOnWriteList.java (rev 0)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/LightWeightCopyOnWriteList.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -0,0 +1,116 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer;
+
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.RandomAccess;
+
+/**
+ * Creates a copy of a reference list when modified.
+ *
+ * @param <T>
+ */
+public class LightWeightCopyOnWriteList<T> extends AbstractList<T> implements RandomAccess {
+
+ private List<T> list;
+ private boolean modified;
+
+ public LightWeightCopyOnWriteList(List<T> list) {
+ this.list = list;
+ }
+
+ @Override
+ public T get(int index) {
+ return list.get(index);
+ }
+
+ public List<T> getList() {
+ return list;
+ }
+
+ public void add(int index, T element) {
+ if (!modified) {
+ List<T> next = new ArrayList<T>(list.size() + 1);
+ next.addAll(list);
+ list = next;
+ modified = true;
+ }
+ list.add(index, element);
+ }
+
+ public T set(int index, T element) {
+ checkModified();
+ return list.set(index, element);
+ }
+
+ private void checkModified() {
+ if (!modified) {
+ list = new ArrayList<T>(list);
+ modified = true;
+ }
+ }
+
+ public boolean addAll(Collection<? extends T> c) {
+ return addAll(size(), c);
+ }
+
+ @Override
+ public boolean addAll(int index, Collection<? extends T> c) {
+ checkModified();
+ return list.addAll(index, c);
+ }
+
+ @Override
+ public T remove(int index) {
+ checkModified();
+ return list.remove(index);
+ }
+
+ @Override
+ public Object[] toArray() {
+ return list.toArray();
+ }
+
+ public <U extends Object> U[] toArray(U[] a) {
+ return list.toArray(a);
+ }
+
+ @Override
+ public void clear() {
+ if (!modified) {
+ list = new ArrayList<T>();
+ modified = true;
+ } else {
+ list.clear();
+ }
+ }
+
+ @Override
+ public int size() {
+ return list.size();
+ }
+
+}
Modified: branches/as7/engine/src/main/java/org/teiid/common/buffer/LobManager.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/LobManager.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/LobManager.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -30,9 +30,10 @@
import java.sql.SQLException;
import java.sql.SQLXML;
import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.types.BaseLob;
@@ -45,6 +46,10 @@
import org.teiid.core.types.SQLXMLImpl;
import org.teiid.core.types.Streamable;
import org.teiid.core.types.XMLType;
+import org.teiid.core.types.InputStreamFactory.BlobInputStreamFactory;
+import org.teiid.core.types.InputStreamFactory.ClobInputStreamFactory;
+import org.teiid.core.types.InputStreamFactory.SQLXMLInputStreamFactory;
+import org.teiid.core.types.InputStreamFactory.StorageMode;
import org.teiid.core.util.ObjectConverterUtil;
import org.teiid.query.QueryPlugin;
import org.teiid.query.sql.symbol.Expression;
@@ -54,9 +59,57 @@
* TODO: for temp tables we may need to have a copy by value management strategy
*/
public class LobManager {
- private Map<String, Streamable<?>> lobReferences = new ConcurrentHashMap<String, Streamable<?>>();
+
+ public enum ReferenceMode {
+ ATTACH,
+ CREATE,
+ REMOVE
+ }
+
+ private static class LobHolder {
+ Streamable<?> lob;
+ int referenceCount = 1;
- public void updateReferences(int[] lobIndexes, List<?> tuple)
+ public LobHolder(Streamable<?> lob) {
+ this.lob = lob;
+ }
+ }
+
+ private Map<String, LobHolder> lobReferences = Collections.synchronizedMap(new HashMap<String, LobHolder>());
+ private boolean inlineLobs = true;
+ private int maxMemoryBytes = DataTypeManager.MAX_LOB_MEMORY_BYTES;
+ private int[] lobIndexes;
+ private FileStore lobStore;
+
+ public LobManager(int[] lobIndexes, FileStore lobStore) {
+ this.lobIndexes = lobIndexes;
+ this.lobStore = lobStore;
+ }
+
+ public LobManager clone() {
+ LobManager clone = new LobManager(lobIndexes, null);
+ clone.inlineLobs = inlineLobs;
+ clone.maxMemoryBytes = maxMemoryBytes;
+ synchronized (lobReferences) {
+ for (Map.Entry<String, LobHolder> entry : lobReferences.entrySet()) {
+ LobHolder lobHolder = new LobHolder(entry.getValue().lob);
+ lobHolder.referenceCount = entry.getValue().referenceCount;
+ clone.lobReferences.put(entry.getKey(), lobHolder);
+ }
+ }
+ return clone;
+ }
+
+ public void setInlineLobs(boolean trackMemoryLobs) {
+ this.inlineLobs = trackMemoryLobs;
+ }
+
+ public void setMaxMemoryBytes(int maxMemoryBytes) {
+ this.maxMemoryBytes = maxMemoryBytes;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void updateReferences(List<?> tuple, ReferenceMode mode)
throws TeiidComponentException {
for (int i = 0; i < lobIndexes.length; i++) {
Object anObj = tuple.get(lobIndexes[i]);
@@ -64,31 +117,64 @@
continue;
}
Streamable lob = (Streamable) anObj;
- if (lob.getReference() == null) {
- lob.setReference(getLobReference(lob.getReferenceStreamId()).getReference());
- } else {
- String id = lob.getReferenceStreamId();
- this.lobReferences.put(id, lob);
+ try {
+ if (lob.getReferenceStreamId() == null || (inlineLobs
+ && (InputStreamFactory.getStorageMode(lob) == StorageMode.MEMORY
+ || lob.length()*(lob instanceof ClobType?2:1) <= maxMemoryBytes))) {
+ lob.setReferenceStreamId(null);
+ continue;
+ }
+ } catch (SQLException e) {
+ //presumably the lob is bad, but let it slide for now
}
+ String id = lob.getReferenceStreamId();
+ LobHolder lobHolder = this.lobReferences.get(id);
+ switch (mode) {
+ case REMOVE:
+ if (lobHolder != null) {
+ lobHolder.referenceCount--;
+ if (lobHolder.referenceCount < 1) {
+ this.lobReferences.remove(id);
+ }
+ }
+ break;
+ case ATTACH:
+ if (lob.getReference() == null) {
+ if (lobHolder == null) {
+ throw new TeiidComponentException(QueryPlugin.Util.getString("ProcessWorker.wrongdata")); //$NON-NLS-1$
+ }
+ lob.setReference(lobHolder.lob.getReference());
+ }
+ break;
+ case CREATE:
+ if (lob.getReference() == null) {
+ throw new TeiidComponentException(QueryPlugin.Util.getString("ProcessWorker.wrongdata")); //$NON-NLS-1$
+ }
+ if (lobHolder == null) {
+ this.lobReferences.put(id, new LobHolder(lob));
+ } else {
+ lobHolder.referenceCount++;
+ }
+ }
}
}
public Streamable<?> getLobReference(String id) throws TeiidComponentException {
- Streamable<?> lob = this.lobReferences.get(id);
+ LobHolder lob = this.lobReferences.get(id);
if (lob == null) {
throw new TeiidComponentException(QueryPlugin.Util.getString("ProcessWorker.wrongdata")); //$NON-NLS-1$
}
- return lob;
+ return lob.lob;
}
- public static int[] getLobIndexes(List expressions) {
+ public static int[] getLobIndexes(List<? extends Expression> expressions) {
if (expressions == null) {
return null;
}
int[] result = new int[expressions.size()];
int resultIndex = 0;
for (int i = 0; i < expressions.size(); i++) {
- Expression expr = (Expression) expressions.get(i);
+ Expression expr = expressions.get(i);
if (DataTypeManager.isLOB(expr.getType()) || expr.getType() == DataTypeManager.DefaultDataClasses.OBJECT) {
result[resultIndex++] = i;
}
@@ -99,12 +185,12 @@
return Arrays.copyOf(result, resultIndex);
}
- public void persist(FileStore lobStore) throws TeiidComponentException {
+ public void persist() throws TeiidComponentException {
// stream the contents of lob into file store.
- byte[] bytes = new byte[102400]; // 100k
+ byte[] bytes = new byte[1 << 14];
- for (Map.Entry<String, Streamable<?>> entry : this.lobReferences.entrySet()) {
- entry.setValue(persistLob(entry.getValue(), lobStore, bytes));
+ for (Map.Entry<String, LobHolder> entry : this.lobReferences.entrySet()) {
+ entry.getValue().lob = persistLob(entry.getValue().lob, lobStore, bytes);
}
}
@@ -115,7 +201,7 @@
try {
BaseLob baseLob = (BaseLob)lob.getReference();
InputStreamFactory isf = baseLob.getStreamFactory();
- if (isf.isPersistent()) {
+ if (isf.getStorageMode() == StorageMode.PERSISTENT) {
return lob;
}
} catch (SQLException e) {
@@ -127,19 +213,15 @@
Streamable<?> persistedLob;
try {
- InputStreamFactory isf = new InputStreamFactory() {
- @Override
- public InputStream getInputStream() throws IOException {
- if (lob instanceof BlobType) {
- return new BlobInputStreamFactory((Blob)lob).getInputStream();
- }
- else if (lob instanceof ClobType) {
- return new ClobInputStreamFactory((Clob)lob).getInputStream();
- }
- return new SQLXMLInputStreamFactory((SQLXML)lob).getInputStream();
- }
- };
- InputStream is = isf.getInputStream();
+ InputStream is = null;
+ if (lob instanceof BlobType) {
+ is = new BlobInputStreamFactory((Blob)lob).getInputStream();
+ }
+ else if (lob instanceof ClobType) {
+ is = new ClobInputStreamFactory((Clob)lob).getInputStream();
+ } else {
+ is = new SQLXMLInputStreamFactory((SQLXML)lob).getInputStream();
+ }
OutputStream fsos = store.createOutputStream();
length = ObjectConverterUtil.write(fsos, is, bytes, -1);
} catch (IOException e) {
@@ -156,8 +238,8 @@
}
@Override
- public boolean isPersistent() {
- return true;
+ public StorageMode getStorageMode() {
+ return StorageMode.PERSISTENT;
}
};
@@ -178,4 +260,13 @@
}
return persistedLob;
}
+
+ public int getLobCount() {
+ return this.lobReferences.size();
+ }
+
+ public void remove() {
+ this.lobReferences.clear();
+
+ }
}
Modified: branches/as7/engine/src/main/java/org/teiid/common/buffer/SPage.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/SPage.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/SPage.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -23,6 +23,7 @@
package org.teiid.common.buffer;
import java.lang.ref.PhantomReference;
+import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.util.ArrayList;
import java.util.Collections;
@@ -31,17 +32,14 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
-import org.teiid.common.buffer.BatchManager.CleanupHook;
-import org.teiid.common.buffer.BatchManager.ManagedBatch;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidRuntimeException;
/**
* A linked list Page entry in the tree
*
- * TODO: return the tuplebatch from getvalues, since that is what we're tracking
- *
* State cloning allows a single storage reference to be shared in many trees.
* A phantom reference is used for proper cleanup once cloned.
*
@@ -56,8 +54,8 @@
static class SearchResult {
int index;
SPage page;
- TupleBatch values;
- public SearchResult(int index, SPage page, TupleBatch values) {
+ List<List<?>> values;
+ public SearchResult(int index, SPage page, List<List<?>> values) {
this.index = index;
this.page = page;
this.values = values;
@@ -68,51 +66,54 @@
private static ReferenceQueue<Object> QUEUE = new ReferenceQueue<Object>();
static class CleanupReference extends PhantomReference<Object> {
- private CleanupHook batch;
+ private Long batch;
+ private Reference<? extends BatchManager> ref;
- public CleanupReference(Object referent, CleanupHook batch) {
+ public CleanupReference(Object referent, Long batch, Reference<? extends BatchManager> ref) {
super(referent, QUEUE);
this.batch = batch;
+ this.ref = ref;
}
public void cleanup() {
try {
- this.batch.cleanup();
+ BatchManager batchManager = ref.get();
+ if (batchManager != null) {
+ batchManager.remove(batch);
+ }
} finally {
this.clear();
}
}
}
-
+
+ private static AtomicLong counter = new AtomicLong();
+
STree stree;
- private int id;
+ private long id;
protected SPage next;
protected SPage prev;
- protected ManagedBatch managedBatch;
- private Object trackingObject;
- protected TupleBatch values;
- protected ArrayList<SPage> children;
- //TODO: could track cloning more completely, which would allow for earlier batch removal
- private boolean cloned;
+ protected Long managedBatch;
+ protected Object trackingObject;
+ protected List<List<?>> values;
+ protected List<SPage> children;
SPage(STree stree, boolean leaf) {
this.stree = stree;
- this.id = stree.counter.getAndIncrement();
+ this.id = counter.getAndIncrement();
stree.pages.put(this.id, this);
- //TODO: this counter is a hack. need a better idea of a storage id
- this.values = new TupleBatch(id, new ArrayList(stree.pageSize/4));
+ this.values = new ArrayList<List<?>>();
if (!leaf) {
- children = new ArrayList<SPage>(stree.pageSize/4);
+ children = new ArrayList<SPage>();
}
}
public SPage clone(STree tree) {
try {
if (this.managedBatch != null && trackingObject == null) {
- cloned = true;
this.trackingObject = new Object();
- CleanupReference managedBatchReference = new CleanupReference(trackingObject, managedBatch.getCleanupHook());
+ CleanupReference managedBatchReference = new CleanupReference(trackingObject, managedBatch, stree.getBatchManager(children == null).getBatchManagerReference());
REFERENCES.add(managedBatchReference);
}
SPage clone = (SPage) super.clone();
@@ -121,7 +122,7 @@
clone.children = new ArrayList<SPage>(children);
}
if (values != null) {
- clone.values = new TupleBatch(stree.counter.getAndIncrement(), new ArrayList<List<?>>(values.getTuples()));
+ clone.values = new ArrayList<List<?>>(values);
}
return clone;
} catch (CloneNotSupportedException e) {
@@ -129,37 +130,37 @@
}
}
- public int getId() {
+ public long getId() {
return id;
}
static SearchResult search(SPage page, List k, LinkedList<SearchResult> parent) throws TeiidComponentException {
- TupleBatch previousValues = null;
+ List<List<?>> previousValues = null;
for (;;) {
- TupleBatch values = page.getValues();
- int index = Collections.binarySearch(values.getTuples(), k, page.stree.comparator);
+ List<List<?>> values = page.getValues();
+ int index = Collections.binarySearch(values, k, page.stree.comparator);
int flippedIndex = - index - 1;
if (previousValues != null) {
if (flippedIndex == 0) {
//systemic weakness of the algorithm
- return new SearchResult(-previousValues.getTuples().size() - 1, page.prev, previousValues);
+ return new SearchResult(-previousValues.size() - 1, page.prev, previousValues);
}
if (parent != null && index != 0) {
page.stree.updateLock.lock();
try {
- index = Collections.binarySearch(values.getTuples(), k, page.stree.comparator);
+ index = Collections.binarySearch(values, k, page.stree.comparator);
if (index != 0) {
//for non-matches move the previous pointer over to this page
SPage childPage = page;
List oldKey = null;
- List newKey = page.stree.extractKey(values.getTuples().get(0));
+ List newKey = page.stree.extractKey(values.get(0));
for (Iterator<SearchResult> desc = parent.descendingIterator(); desc.hasNext();) {
SearchResult sr = desc.next();
int parentIndex = Math.max(0, -sr.index - 2);
if (oldKey == null) {
- oldKey = sr.values.getTuples().set(parentIndex, newKey);
- } else if (page.stree.comparator.compare(oldKey, sr.values.getTuples().get(parentIndex)) == 0 ) {
- sr.values.getTuples().set(parentIndex, newKey);
+ oldKey = sr.values.set(parentIndex, newKey);
+ } else if (page.stree.comparator.compare(oldKey, sr.values.get(parentIndex)) == 0 ) {
+ sr.values.set(parentIndex, newKey);
} else {
break;
}
@@ -173,7 +174,7 @@
}
}
}
- if (flippedIndex != values.getTuples().size() || page.next == null) {
+ if (flippedIndex != values.size() || page.next == null) {
return new SearchResult(index, page, values);
}
previousValues = values;
@@ -181,36 +182,32 @@
}
}
- protected void setValues(TupleBatch values) throws TeiidComponentException {
- if (managedBatch != null && !cloned) {
- managedBatch.remove();
+ protected void setValues(List<List<?>> values) throws TeiidComponentException {
+ if (values instanceof LightWeightCopyOnWriteList<?>) {
+ values = ((LightWeightCopyOnWriteList<List<?>>)values).getList();
}
- if (values.getTuples().size() < MIN_PERSISTENT_SIZE) {
+ if (managedBatch != null && trackingObject == null) {
+ stree.getBatchManager(children == null).remove(managedBatch);
+ managedBatch = null;
+ trackingObject = null;
+ }
+ if (values.size() < MIN_PERSISTENT_SIZE) {
this.values = values;
return;
- }
- this.values = null;
- if (children != null) {
- values.setDataTypes(stree.keytypes);
- } else {
- values.setDataTypes(stree.types);
+ } else if (stree.batchInsert && children == null && values.size() < stree.leafSize) {
+ this.values = values;
+ stree.incompleteInsert = this;
+ return;
}
- if (cloned) {
- values.setRowOffset(stree.counter.getAndIncrement());
- cloned = false;
- trackingObject = null;
- }
- if (children != null) {
- managedBatch = stree.keyManager.createManagedBatch(values, true);
- } else {
- managedBatch = stree.leafManager.createManagedBatch(values, stree.preferMemory);
- }
+ this.values = null;
+ this.trackingObject = null;
+ managedBatch = stree.getBatchManager(children == null).createManagedBatch(values);
}
-
+
protected void remove(boolean force) {
if (managedBatch != null) {
- if (force || !cloned) {
- managedBatch.remove();
+ if (force || trackingObject == null) {
+ stree.getBatchManager(children == null).remove(managedBatch);
}
managedBatch = null;
trackingObject = null;
@@ -219,7 +216,7 @@
children = null;
}
- protected TupleBatch getValues() throws TeiidComponentException {
+ protected List<List<?>> getValues() throws TeiidComponentException {
if (values != null) {
return values;
}
@@ -234,19 +231,20 @@
REFERENCES.remove(ref);
ref.cleanup();
}
- if (children != null) {
- return managedBatch.getBatch(true, stree.keytypes);
+ List<List<?>> result = stree.getBatchManager(children == null).getBatch(managedBatch, true);
+ if (trackingObject != null) {
+ return new LightWeightCopyOnWriteList<List<?>>(result);
}
- return managedBatch.getBatch(true, stree.types);
+ return result;
}
- static void merge(LinkedList<SearchResult> places, TupleBatch nextValues, SPage current, TupleBatch currentValues)
+ static void merge(LinkedList<SearchResult> places, List<List<?>> nextValues, SPage current, List<List<?>> currentValues)
throws TeiidComponentException {
SearchResult parent = places.peekLast();
if (parent != null) {
- correctParents(parent.page, nextValues.getTuples().get(0), current.next, current);
+ correctParents(parent.page, nextValues.get(0), current.next, current);
}
- currentValues.getTuples().addAll(nextValues.getTuples());
+ currentValues.addAll(nextValues);
if (current.children != null) {
current.children.addAll(current.next.children);
}
@@ -292,19 +290,19 @@
public String toString() {
StringBuilder result = new StringBuilder();
try {
- TupleBatch tb = getValues();
- result.append(tb.getBeginRow());
+ List<List<?>> tb = getValues();
+ result.append(id);
if (children == null) {
- if (tb.getTuples().size() <= 1) {
- result.append(tb.getTuples());
+ if (tb.size() <= 1) {
+ result.append(tb);
} else {
- result.append("[").append(tb.getTuples().get(0)).append(" . ").append(tb.getTuples().size()). //$NON-NLS-1$ //$NON-NLS-2$
- append(" . ").append(tb.getTuples().get(tb.getTuples().size() - 1)).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
+ result.append("[").append(tb.get(0)).append(" . ").append(tb.size()). //$NON-NLS-1$ //$NON-NLS-2$
+ append(" . ").append(tb.get(tb.size() - 1)).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
}
} else {
result.append("["); //$NON-NLS-1$
for (int i = 0; i < children.size(); i++) {
- result.append(tb.getTuples().get(i)).append("->").append(children.get(i).getValues().getBeginRow()); //$NON-NLS-1$
+ result.append(tb.get(i)).append("->").append(children.get(i).getId()); //$NON-NLS-1$
if (i < children.size() - 1) {
result.append(", "); //$NON-NLS-1$
}
Modified: branches/as7/engine/src/main/java/org/teiid/common/buffer/STree.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/STree.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/STree.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -27,15 +27,16 @@
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
import org.teiid.client.BatchSerializer;
+import org.teiid.common.buffer.LobManager.ReferenceMode;
import org.teiid.common.buffer.SPage.SearchResult;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidRuntimeException;
@@ -51,23 +52,23 @@
public enum InsertMode {ORDERED, NEW, UPDATE}
- private static final Random seedGenerator = new Random();
+ private static final Random seedGenerator = new Random(0);
protected int randomSeed;
private int mask = 1;
private int shift = 1;
- protected AtomicInteger counter = new AtomicInteger();
- protected ConcurrentHashMap<Integer, SPage> pages = new ConcurrentHashMap<Integer, SPage>();
+ protected HashMap<Long, SPage> pages = new HashMap<Long, SPage>();
protected volatile SPage[] header = new SPage[] {new SPage(this, true)};
protected BatchManager keyManager;
protected BatchManager leafManager;
protected ListNestedSortComparator comparator;
- protected int pageSize;
+ private int pageSize;
+ protected int leafSize;
protected int keyLength;
- protected String[] types;
- protected String[] keytypes;
- protected boolean preferMemory;
+ protected boolean batchInsert;
+ protected SPage incompleteInsert;
+ protected LobManager lobManager;
protected ReentrantLock updateLock = new ReentrantLock();
@@ -77,10 +78,12 @@
BatchManager leafManager,
final ListNestedSortComparator comparator,
int pageSize,
+ int leafSize,
int keyLength,
- String[] types) {
+ LobManager lobManager) {
randomSeed = seedGenerator.nextInt() | 0x00000100; // ensure nonzero
this.keyManager = manager;
+ manager.setPrefersMemory(true);
this.leafManager = leafManager;
this.comparator = comparator;
this.pageSize = Math.max(pageSize, SPage.MIN_PERSISTENT_SIZE);
@@ -91,24 +94,27 @@
mask <<= 1;
mask++;
}
+ this.leafSize = leafSize;
this.keyLength = keyLength;
- this.types = types;
- this.keytypes = Arrays.copyOf(types, keyLength);
+ this.lobManager = lobManager;
}
public STree clone() {
updateLock.lock();
try {
STree clone = (STree) super.clone();
+ if (lobManager != null) {
+ clone.lobManager = lobManager.clone();
+ }
clone.updateLock = new ReentrantLock();
clone.rowCount = new AtomicInteger(rowCount.get());
//clone the pages
- clone.pages = new ConcurrentHashMap<Integer, SPage>(pages);
- for (Map.Entry<Integer, SPage> entry : clone.pages.entrySet()) {
+ clone.pages = new HashMap<Long, SPage>(pages);
+ for (Map.Entry<Long, SPage> entry : clone.pages.entrySet()) {
entry.setValue(entry.getValue().clone(clone));
}
//reset the pointers
- for (Map.Entry<Integer, SPage> entry : clone.pages.entrySet()) {
+ for (Map.Entry<Long, SPage> entry : clone.pages.entrySet()) {
SPage clonePage = entry.getValue();
clonePage.next = clone.getPage(clonePage.next);
clonePage.prev = clone.getPage(clonePage.prev);
@@ -141,23 +147,41 @@
SPage page = header[0];
oos.writeInt(this.rowCount.get());
while (true) {
- TupleBatch batch = page.getValues();
- BatchSerializer.writeBatch(oos, types, batch.getAllTuples());
+ List<List<?>> batch = page.getValues();
+ BatchSerializer.writeBatch(oos, leafManager.getTypes(), batch);
if (page.next == null) {
break;
}
}
}
+ public void setBatchInsert(boolean batchInsert) throws TeiidComponentException {
+ if (this.batchInsert == batchInsert) {
+ return;
+ }
+ this.batchInsert = batchInsert;
+ if (batchInsert || incompleteInsert == null) {
+ return;
+ }
+ SPage toFlush = incompleteInsert;
+ incompleteInsert = null;
+ if (toFlush.managedBatch != null) {
+ return;
+ }
+ toFlush.setValues(toFlush.getValues());
+ }
+
public void readValuesFrom(ObjectInputStream ois) throws IOException, ClassNotFoundException, TeiidComponentException {
int size = ois.readInt();
int sizeHint = this.getExpectedHeight(size);
+ batchInsert = true;
while (this.getRowCount() < size) {
- List[] batch = BatchSerializer.readBatch(ois, types);
+ List<List<Object>> batch = BatchSerializer.readBatch(ois, leafManager.getTypes());
for (List list : batch) {
this.insert(list, InsertMode.ORDERED, sizeHint);
}
}
+ batchInsert = false;
}
protected SPage findChildTail(SPage page) {
@@ -219,7 +243,7 @@
if (places != null) {
places.add(s);
}
- if ((s.index == -1 && s.page == header[i]) || s.values.getTuples().isEmpty()) {
+ if ((s.index == -1 && s.page == header[i]) || s.values.isEmpty()) {
x = null;
continue; //start at the beginning of the next level
}
@@ -234,7 +258,7 @@
if (!matched) {
return null;
}
- return s.values.getTuples().get(index);
+ return s.values.get(index);
}
x = x.children.get(index);
}
@@ -248,13 +272,16 @@
public List insert(List tuple, InsertMode mode, int sizeHint) throws TeiidComponentException {
LinkedList<SearchResult> places = new LinkedList<SearchResult>();
List match = null;
+ if (this.lobManager != null) {
+ this.lobManager.updateReferences(tuple, ReferenceMode.CREATE);
+ }
if (mode == InsertMode.ORDERED) {
SPage last = null;
while (last == null || last.children != null) {
last = findChildTail(last);
//TODO: do this lazily
- TupleBatch batch = last.getValues();
- places.add(new SearchResult(-batch.getTuples().size() -1, last, batch));
+ List<List<?>> batch = last.getValues();
+ places.add(new SearchResult(-batch.size() -1, last, batch));
}
} else {
match = find(tuple, places);
@@ -264,8 +291,11 @@
}
SearchResult last = places.getLast();
SPage page = last.page;
- last.values.getTuples().set(last.index, tuple);
+ last.values.set(last.index, tuple);
page.setValues(last.values);
+ if (this.lobManager != null) {
+ this.lobManager.updateReferences(tuple, ReferenceMode.REMOVE);
+ }
return match;
}
}
@@ -277,10 +307,10 @@
} else {
level = randomLevel();
}
- } else if (!places.isEmpty() && places.getLast().values.getTuples().size() == pageSize) {
+ } else if (!places.isEmpty() && places.getLast().values.size() == getPageSize(true)) {
int row = rowCount.get();
- while (row != 0 && row%pageSize == 0) {
- row = (row - pageSize + 1)/pageSize;
+ while (row != 0 && row%getPageSize(true) == 0) {
+ row = (row - getPageSize(true) + 1)/getPageSize(true);
level++;
}
}
@@ -293,8 +323,8 @@
for (int i = 0; i <= level; i++) {
if (places.isEmpty()) {
SPage newHead = new SPage(this, false);
- TupleBatch batch = newHead.getValues();
- batch.getTuples().add(key);
+ List<List<?>> batch = newHead.getValues();
+ batch.add(key);
newHead.setValues(batch);
newHead.children.add(page);
header[i] = newHead;
@@ -313,9 +343,9 @@
return 0;
}
int logSize = 1;
- while (sizeHint > this.pageSize) {
+ while (sizeHint > this.getPageSize(logSize==0)) {
logSize++;
- sizeHint/=this.pageSize;
+ sizeHint/=this.getPageSize(logSize==0);
}
return logSize;
}
@@ -330,10 +360,10 @@
SPage insert(List k, SearchResult result, SearchResult parent, Object value, boolean ordered) throws TeiidComponentException {
SPage page = result.page;
int index = -result.index - 1;
- if (result.values.getTuples().size() == pageSize) {
- boolean leaf = !(value instanceof SPage);
+ boolean leaf = !(value instanceof SPage);
+ if (result.values.size() == getPageSize(leaf)) {
SPage nextPage = new SPage(this, leaf);
- TupleBatch nextValues = nextPage.getValues();
+ List<List<?>> nextValues = nextPage.getValues();
nextPage.next = page.next;
nextPage.prev = page;
if (nextPage.next != null) {
@@ -343,21 +373,21 @@
boolean inNext = false;
if (!ordered) {
//split the values
- nextValues.getTuples().addAll(result.values.getTuples().subList(pageSize/2, pageSize));
- result.values.getTuples().subList(pageSize/2, pageSize).clear();
+ nextValues.addAll(result.values.subList(getPageSize(leaf)/2, getPageSize(leaf)));
+ result.values.subList(getPageSize(leaf)/2, getPageSize(leaf)).clear();
if (!leaf) {
- nextPage.children.addAll(page.children.subList(pageSize/2, pageSize));
- page.children.subList(pageSize/2, pageSize).clear();
+ nextPage.children.addAll(page.children.subList(getPageSize(leaf)/2, getPageSize(false)));
+ page.children.subList(getPageSize(false)/2, getPageSize(false)).clear();
}
- if (index <= pageSize/2) {
+ if (index <= getPageSize(leaf)/2) {
setValue(index, k, value, result.values, page);
} else {
inNext = true;
- setValue(index - pageSize/2, k, value, nextValues, nextPage);
+ setValue(index - getPageSize(leaf)/2, k, value, nextValues, nextPage);
}
page.setValues(result.values);
if (parent != null) {
- List min = nextPage.getValues().getTuples().get(0);
+ List min = nextPage.getValues().get(0);
SPage.correctParents(parent.page, min, page, nextPage);
}
} else {
@@ -375,12 +405,12 @@
return page;
}
- static void setValue(int index, List key, Object value, TupleBatch values, SPage page) {
+ static void setValue(int index, List key, Object value, List<List<?>> values, SPage page) {
if (value instanceof SPage) {
- values.getTuples().add(index, key);
+ values.add(index, key);
page.children.add(index, (SPage) value);
} else {
- values.getTuples().add(index, (List)value);
+ values.add(index, (List)value);
}
}
@@ -396,11 +426,13 @@
if (searchResult.index < 0) {
continue;
}
- searchResult.values.getTuples().remove(searchResult.index);
+ searchResult.values.remove(searchResult.index);
+ boolean leaf = true;
if (searchResult.page.children != null) {
+ leaf = false;
searchResult.page.children.remove(searchResult.index);
}
- int size = searchResult.values.getTuples().size();
+ int size = searchResult.values.size();
if (size == 0) {
if (header[i] != searchResult.page) {
searchResult.page.remove(false);
@@ -424,18 +456,18 @@
header[0] = new SPage(this, true);
}
continue;
- } else if (size < pageSize/2) {
+ } else if (size < getPageSize(leaf)/2) {
//check for merge
if (searchResult.page.next != null) {
- TupleBatch nextValues = searchResult.page.next.getValues();
- if (nextValues.getTuples().size() < pageSize/4) {
+ List<List<?>> nextValues = searchResult.page.next.getValues();
+ if (nextValues.size() < getPageSize(leaf)/4) {
SPage.merge(places, nextValues, searchResult.page, searchResult.values);
continue;
}
}
if (searchResult.page.prev != null) {
- TupleBatch prevValues = searchResult.page.prev.getValues();
- if (prevValues.getTuples().size() < pageSize/4) {
+ List<List<?>> prevValues = searchResult.page.prev.getValues();
+ if (prevValues.size() < getPageSize(leaf)/4) {
SPage.merge(places, searchResult.values, searchResult.page.prev, prevValues);
continue;
}
@@ -443,11 +475,14 @@
}
searchResult.page.setValues(searchResult.values);
}
+ if (lobManager != null) {
+ lobManager.updateReferences(tuple, ReferenceMode.REMOVE);
+ }
return tuple;
}
public void remove() {
- truncate(false);
+ truncate(true);
this.keyManager.remove();
this.leafManager.remove();
}
@@ -494,11 +529,11 @@
}
public void setPreferMemory(boolean preferMemory) {
- this.preferMemory = preferMemory;
+ this.leafManager.setPrefersMemory(preferMemory);
}
public boolean isPreferMemory() {
- return preferMemory;
+ return this.leafManager.prefersMemory();
}
public ListNestedSortComparator getComparator() {
@@ -530,4 +565,26 @@
this.comparator.setSortParameters(sortParameters);
}
+ public void clearClonedFlags() {
+ for (SPage page : pages.values()) {
+ page.trackingObject = null;
+ //we don't really care about using synchronization or a volatile here
+ //since the worst case is that we'll just use gc cleanup
+ }
+ }
+
+ public int getPageSize(boolean leaf) {
+ if (leaf) {
+ return leafSize;
+ }
+ return pageSize;
+ }
+
+ BatchManager getBatchManager(boolean leaf) {
+ if (leaf) {
+ return leafManager;
+ }
+ return keyManager;
+ }
+
}
\ No newline at end of file
Copied: branches/as7/engine/src/main/java/org/teiid/common/buffer/Serializer.java (from rev 3506, trunk/engine/src/main/java/org/teiid/common/buffer/Serializer.java)
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/Serializer.java (rev 0)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/Serializer.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+/**
+ * Responsible for serializing {@link CacheEntry}s
+ * @param <T>
+ */
+public interface Serializer<T> {
+ void serialize(T obj, ObjectOutputStream oos) throws IOException;
+ T deserialize(ObjectInputStream ois) throws IOException, ClassNotFoundException;
+ boolean useSoftCache();
+ Long getId();
+}
\ No newline at end of file
Modified: branches/as7/engine/src/main/java/org/teiid/common/buffer/TupleBatch.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/TupleBatch.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/TupleBatch.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -22,17 +22,11 @@
package org.teiid.common.buffer;
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import org.teiid.client.BatchSerializer;
-
/**
* Represents a set of indexed tuples. The {@link #getBeginRow beginning row}
* is the first row contained in this batch; if it equals "1" then it is the
@@ -40,28 +34,17 @@
* tuples. The {@link #getEndRow ending row} is the last row contained in
* this tuple batch; it is equal to the beginning row plus the
* {@link #getRowCount number of rows} contained in this batch, minus one.
- * This object is immutable and Serializable;
*/
-public class TupleBatch implements Externalizable {
+public class TupleBatch {
private static final long serialVersionUID = 6304443387337336957L;
private int rowOffset;
- private List<List<?>> tuples;
+ protected List<List<?>> tuples;
// Optional state
private boolean terminationFlag = false;
- // for distributed cache purposes
- private String[] preservedTypes;
-
- /**
- * Contains ordered data types of each of the columns in the batch. Although it is not serialized,
- * this array is a serialization aid and must be set before serialization and deserialization using
- * the setDataTypes method.
- */
- private transient String[] types;
-
/** Required to honor Externalizable contract */
public TupleBatch() {
}
@@ -152,14 +135,6 @@
this.terminationFlag = terminationFlag;
}
- public void setDataTypes(String[] types) {
- this.types = types;
- }
-
- public String[] getDataTypes() {
- return types;
- }
-
public boolean containsRow(int row) {
return rowOffset <= row && getEndRow() >= row;
}
@@ -179,31 +154,8 @@
return s.toString();
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- rowOffset = in.readInt();
- terminationFlag = in.readBoolean();
- preservedTypes = (String[])in.readObject();
- if (types == null) {
- types = preservedTypes;
- }
- tuples = new ArrayList<List<?>>();
- for (List tuple : BatchSerializer.readBatch(in, types)) {
- tuples.add(tuple);
- }
- }
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeInt(this.rowOffset);
- out.writeBoolean(terminationFlag);
- out.writeObject(this.preservedTypes);
- BatchSerializer.writeBatch(out, types, getAllTuples());
- }
-
public void setRowOffset(int rowOffset) {
this.rowOffset = rowOffset;
}
-
- public void preserveTypes() {
- this.preservedTypes = types;
- }
}
Property changes on: branches/as7/engine/src/main/java/org/teiid/common/buffer/TupleBatch.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/main/java/org/teiid/common/buffer/TupleBatch.java:3220-3275
/trunk/engine/src/main/java/org/teiid/common/buffer/TupleBatch.java:3188-3450
+ /branches/7.4.x/engine/src/main/java/org/teiid/common/buffer/TupleBatch.java:3220-3275
/trunk/engine/src/main/java/org/teiid/common/buffer/TupleBatch.java:3188-3450,3452-3506
Modified: branches/as7/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -48,7 +48,7 @@
private SPage bound;
private int boundIndex = -1;
- private TupleBatch values;
+ private List<List<?>> values;
private boolean updated;
private boolean direction;
@@ -106,7 +106,7 @@
if (boundIndex < 0) {
//we are guaranteed by find to not get back the -1 index, unless
//there are no tuples, in which case a bound of -1 is fine
- boundIndex = Math.min(upper.values.getTuples().size(), -boundIndex -1) - 1;
+ boundIndex = Math.min(upper.values.size(), -boundIndex -1) - 1;
}
if (!direction) {
values = upper.values;
@@ -122,7 +122,7 @@
if (page != bound || values == null) {
values = bound.getValues();
}
- boundIndex = values.getTuples().size() - 1;
+ boundIndex = values.size() - 1;
}
}
@@ -173,14 +173,14 @@
continue;
}
if (values != null) {
- int possibleIndex = Collections.binarySearch(values.getTuples(), newValue, tree.comparator);
+ int possibleIndex = Collections.binarySearch(values, newValue, tree.comparator);
if (possibleIndex >= 0) {
//value exists in the current page
index = possibleIndex;
- return values.getTuples().get(possibleIndex);
+ return values.get(possibleIndex);
}
//check for end/terminal conditions
- if (direction && possibleIndex == -values.getTuples().size() -1) {
+ if (direction && possibleIndex == -values.size() -1) {
if (page.next == null) {
resetState();
return null;
@@ -199,7 +199,7 @@
if (!setPage(newValue)) {
continue;
}
- return values.getTuples().get(index);
+ return values.get(index);
}
if (page == null) {
if (inPartial) {
@@ -213,11 +213,11 @@
if (direction) {
index = 0;
} else {
- index = values.getTuples().size() - 1;
+ index = values.size() - 1;
}
}
- if (index >= 0 && index < values.getTuples().size()) {
- List<?> result = values.getTuples().get(index);
+ if (index >= 0 && index < values.size()) {
+ List<?> result = values.get(index);
if (page == bound && index == boundIndex) {
resetState();
page = null; //terminate
@@ -257,7 +257,7 @@
* @throws TeiidComponentException
*/
public void update(List<?> tuple) throws TeiidComponentException {
- values.getTuples().set(index - getOffset(), tuple);
+ values.set(index - getOffset(), tuple);
updated = true;
}
Modified: branches/as7/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -28,7 +28,7 @@
import java.util.Map;
import java.util.TreeMap;
-import org.teiid.common.buffer.BatchManager.ManagedBatch;
+import org.teiid.common.buffer.LobManager.ReferenceMode;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.types.Streamable;
@@ -64,36 +64,32 @@
private BatchManager manager;
private String tupleSourceID;
private List<? extends Expression> schema;
- private String[] types;
private int batchSize;
private int rowCount;
private boolean isFinal;
- private TreeMap<Integer, BatchManager.ManagedBatch> batches = new TreeMap<Integer, BatchManager.ManagedBatch>();
+ private TreeMap<Integer, Long> batches = new TreeMap<Integer, Long>();
private ArrayList<List<?>> batchBuffer;
private boolean removed;
private boolean forwardOnly;
- private boolean prefersMemory;
private LobManager lobManager;
- private int[] lobIndexes;
private String uuid;
- private FileStore lobStore;
- public TupleBuffer(BatchManager manager, String id, List<? extends Expression> schema, int[] lobIndexes, int batchSize) {
+ public TupleBuffer(BatchManager manager, String id, List<? extends Expression> schema, LobManager lobManager, int batchSize) {
this.manager = manager;
this.tupleSourceID = id;
this.schema = schema;
- this.types = getTypeNames(schema);
- this.lobIndexes = lobIndexes;
- if (this.lobIndexes != null) {
- this.lobManager = new LobManager();
- this.lobStore = this.manager.createStorage("_lobs"); //$NON-NLS-1$
- this.lobStore.setCleanupReference(this);
- }
+ this.lobManager = lobManager;
this.batchSize = batchSize;
}
+ public void setInlineLobs(boolean inline) {
+ if (this.lobManager != null) {
+ this.lobManager.setInlineLobs(inline);
+ }
+ }
+
public String getId() {
if (this.uuid == null) {
this.uuid = java.util.UUID.randomUUID().toString();
@@ -106,12 +102,12 @@
}
public boolean isLobs() {
- return lobIndexes != null;
+ return lobManager != null;
}
public void addTuple(List<?> tuple) throws TeiidComponentException {
if (isLobs()) {
- lobManager.updateReferences(lobIndexes, tuple);
+ lobManager.updateReferences(tuple, ReferenceMode.CREATE);
}
this.rowCount++;
if (batchBuffer == null) {
@@ -119,7 +115,7 @@
}
batchBuffer.add(tuple);
if (batchBuffer.size() == batchSize) {
- saveBatch(false, false);
+ saveBatch(false);
}
}
@@ -138,7 +134,7 @@
//add the lob references only, since they may still be referenced later
if (isLobs()) {
for (List<?> tuple : batch.getTuples()) {
- lobManager.updateReferences(lobIndexes, tuple);
+ lobManager.updateReferences(tuple, ReferenceMode.CREATE);
}
}
}
@@ -148,7 +144,7 @@
throws TeiidComponentException {
assert this.rowCount <= rowCount;
if (this.rowCount != rowCount) {
- saveBatch(false, true);
+ saveBatch(true);
this.rowCount = rowCount;
}
}
@@ -157,15 +153,15 @@
if (this.batchBuffer != null) {
this.batchBuffer.clear();
}
- for (BatchManager.ManagedBatch batch : this.batches.values()) {
- batch.remove();
+ for (Long batch : this.batches.values()) {
+ this.manager.remove(batch);
}
this.batches.clear();
}
public void persistLobs() throws TeiidComponentException {
if (this.lobManager != null) {
- this.lobManager.persist(this.lobStore);
+ this.lobManager.persist();
}
}
@@ -174,26 +170,21 @@
* @throws TeiidComponentException
*/
public void saveBatch() throws TeiidComponentException {
- this.saveBatch(false, false);
+ this.saveBatch(false);
}
- void saveBatch(boolean finalBatch, boolean force) throws TeiidComponentException {
+ void saveBatch(boolean force) throws TeiidComponentException {
Assertion.assertTrue(!this.isRemoved());
if (batchBuffer == null || batchBuffer.isEmpty() || (!force && batchBuffer.size() < Math.max(1, batchSize / 32))) {
return;
}
- TupleBatch writeBatch = new TupleBatch(rowCount - batchBuffer.size() + 1, batchBuffer);
- if (finalBatch) {
- writeBatch.setTerminationFlag(true);
- }
- writeBatch.setDataTypes(types);
- BatchManager.ManagedBatch mbatch = manager.createManagedBatch(writeBatch, prefersMemory);
- this.batches.put(writeBatch.getBeginRow(), mbatch);
+ Long mbatch = manager.createManagedBatch(batchBuffer);
+ this.batches.put(rowCount - batchBuffer.size() + 1, mbatch);
batchBuffer = null;
}
public void close() throws TeiidComponentException {
- saveBatch(true, false);
+ saveBatch(false);
this.isFinal = true;
}
@@ -204,6 +195,8 @@
* @param row
* @return
* @throws TeiidComponentException
+ *
+ * TODO: a method to get the raw batch
*/
public TupleBatch getBatch(int row) throws TeiidComponentException {
TupleBatch result = null;
@@ -218,17 +211,20 @@
if (this.batchBuffer != null && !this.batchBuffer.isEmpty()) {
//this is just a sanity check to ensure we're not holding too many
//hard references to batches.
- saveBatch(isFinal, false);
+ saveBatch(false);
}
- Map.Entry<Integer, BatchManager.ManagedBatch> entry = batches.floorEntry(row);
+ Map.Entry<Integer, Long> entry = batches.floorEntry(row);
Assertion.isNotNull(entry);
- BatchManager.ManagedBatch batch = entry.getValue();
- result = batch.getBatch(!forwardOnly, types);
+ Long batch = entry.getValue();
+ List<List<?>> rows = manager.getBatch(batch, !forwardOnly);
+ result = new TupleBatch(entry.getKey(), rows);
+ if (isFinal && result.getEndRow() == rowCount) {
+ result.setTerminationFlag(true);
+ }
if (forwardOnly) {
batches.remove(entry.getKey());
}
}
- result.setDataTypes(types);
if (isFinal && result.getEndRow() == rowCount) {
result.setTerminationFlag(true);
}
@@ -240,8 +236,8 @@
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Removing TupleBuffer:", this.tupleSourceID); //$NON-NLS-1$
}
- if (this.lobStore != null) {
- this.lobStore.remove();
+ if (this.lobManager != null) {
+ this.lobManager.remove();
}
this.batchBuffer = null;
purge();
@@ -359,18 +355,18 @@
}
public void setPrefersMemory(boolean prefersMemory) {
- this.prefersMemory = prefersMemory;
- for (ManagedBatch batch : this.batches.values()) {
- batch.setPrefersMemory(prefersMemory);
- }
+ this.manager.setPrefersMemory(prefersMemory);
}
- public boolean isPrefersMemory() {
- return prefersMemory;
+ public String[] getTypes() {
+ return manager.getTypes();
}
- public String[] getTypes() {
- return types;
+ public int getLobCount() {
+ if (this.lobManager == null) {
+ return 0;
+ }
+ return this.lobManager.getLobCount();
}
}
Property changes on: branches/as7/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java:3149-3217,3220-3275,3340-3349
/trunk/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java:3188-3450
+ /branches/7.4.x/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java:3149-3217,3220-3275,3340-3349
/trunk/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java:3188-3450,3452-3506
Copied: branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/BlockBitSetTree.java (from rev 3506, trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockBitSetTree.java)
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/BlockBitSetTree.java (rev 0)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/BlockBitSetTree.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -0,0 +1,191 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+ package org.teiid.common.buffer.impl;
+
+import java.util.BitSet;
+
+import org.teiid.common.buffer.impl.FileStoreCache.BlockInfo;
+
+/**
+ * Extends a {@link BitSet} by adding a cumulative total and a
+ * first level index to speed queries against large bitsets.
+ */
+public class BlockBitSetTree {
+
+ private static final int LOG_BITS_PER_BLOCK = FileStoreCache.LOG_BLOCK_SIZE + 3;
+ private static final int MAX_TOP_VALUE = 1 << LOG_BITS_PER_BLOCK;
+ private int maxIndex;
+ private int bitsSet;
+ private int[] topVals;
+ private BlockManager blockManager;
+ private int blockCount = 0;
+
+ public BlockBitSetTree(int maxIndex, BlockManager blockManager) {
+ this.maxIndex = maxIndex;
+ this.blockManager = blockManager;
+ this.topVals = new int[(maxIndex >> (FileStoreCache.LOG_BLOCK_SIZE + 3)) + 1];
+ }
+
+ public int getMaxIndex() {
+ return maxIndex;
+ }
+
+ /**
+ * Set the given bit at the index.
+ * @param bitIndex
+ * @param value
+ */
+ public synchronized void set(int bitIndex, boolean value) {
+ getOrSet(bitIndex, value, true);
+ }
+
+ public synchronized boolean get(int bitIndex) {
+ return getOrSet(bitIndex, false, false);
+ }
+
+ private boolean getOrSet(int bitIndex, boolean value, boolean update) {
+ if (bitIndex > maxIndex) {
+ throw new ArrayIndexOutOfBoundsException(bitIndex);
+ }
+ int blockIndex = bitIndex>>LOG_BITS_PER_BLOCK;
+ BlockInfo bb = null;
+ if (blockIndex >= blockCount) {
+ if (!update) {
+ return false;
+ }
+ for (; blockCount < blockIndex+1; blockCount++) {
+ bb = blockManager.allocateBlock(blockCount);
+ bb.buf.position(0);
+ int longsPerBlock = FileStoreCache.BLOCK_SIZE >> 6;
+ for (int j = 0; j < longsPerBlock; j++) {
+ bb.buf.putLong(0);
+ }
+ }
+ } else {
+ bb = blockManager.getBlock(blockIndex);
+ }
+ int relativeIndex = bitIndex&(MAX_TOP_VALUE-1);
+ int longByteIndex = (relativeIndex>>6)<<3;
+ long word = bb.buf.getLong(longByteIndex);
+ long mask = 1L << bitIndex;
+ boolean currentValue = ((word & mask) != 0);
+ if (!update) {
+ return currentValue;
+ }
+ if (currentValue == value) {
+ return currentValue;
+ }
+ if (value) {
+ word |= mask;
+ } else {
+ word &= ~mask;
+ }
+ bb.buf.putLong(longByteIndex, word);
+ blockManager.updateBlock(bb);
+ int topIndex = bitIndex >> LOG_BITS_PER_BLOCK;
+ int increment = value?1:-1;
+ bitsSet+=increment;
+ topVals[topIndex]+=increment;
+ return currentValue;
+ }
+
+ public synchronized int getBitsSet() {
+ return bitsSet;
+ }
+
+ public synchronized int nextClearBit(int fromIndex) {
+ int start = fromIndex >> LOG_BITS_PER_BLOCK;
+ for (int i = start; i < topVals.length; i++) {
+ if (topVals[i] == MAX_TOP_VALUE) {
+ continue;
+ }
+ if (topVals[i] == 0) {
+ if (i == start) {
+ return fromIndex;
+ }
+ return i * MAX_TOP_VALUE;
+ }
+ int relativeIndex = 0;
+ if (i == start) {
+ relativeIndex = fromIndex&(MAX_TOP_VALUE-1);
+ }
+ BlockInfo bb = blockManager.getBlock(i);
+
+ int longByteIndex = (relativeIndex>>6)<<3;
+
+ long word = ~bb.buf.getLong(longByteIndex) & (-1l << relativeIndex);
+
+ while (true) {
+ if (word != 0) {
+ return longByteIndex*8 + (i * MAX_TOP_VALUE) + Long.numberOfTrailingZeros(word);
+ }
+ longByteIndex+=8;
+ if (longByteIndex > FileStoreCache.BLOCK_MASK) {
+ break;
+ }
+ word = ~bb.buf.getLong(longByteIndex);
+ }
+ }
+ return -1;
+ }
+
+ public synchronized int nextSetBit(int fromIndex) {
+ if (bitsSet == 0) {
+ return -1;
+ }
+ int start = fromIndex >> LOG_BITS_PER_BLOCK;
+ for (int i = start; i < topVals.length; i++) {
+ if (topVals[i] == 0) {
+ continue;
+ }
+ if (topVals[i] == MAX_TOP_VALUE) {
+ if (i == start) {
+ return fromIndex;
+ }
+ return i * MAX_TOP_VALUE;
+ }
+ int relativeIndex = 0;
+ if (i == start) {
+ relativeIndex = fromIndex&(MAX_TOP_VALUE-1);
+ }
+ BlockInfo bb = blockManager.getBlock(i);
+
+ int longByteIndex = (relativeIndex>>6)<<3;
+
+ long word = bb.buf.getLong(longByteIndex) & (-1l << relativeIndex);
+
+ while (true) {
+ if (word != 0) {
+ return longByteIndex*8 + (i * MAX_TOP_VALUE) + Long.numberOfTrailingZeros(word);
+ }
+ longByteIndex+=8;
+ if (longByteIndex > FileStoreCache.BLOCK_MASK) {
+ break;
+ }
+ word = bb.buf.getLong(longByteIndex);
+ }
+ }
+ return -1;
+ }
+
+}
Copied: branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/BlockClosedLongIntHashTable.java (from rev 3506, trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockClosedLongIntHashTable.java)
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/BlockClosedLongIntHashTable.java (rev 0)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/BlockClosedLongIntHashTable.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -0,0 +1,238 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer.impl;
+
+import java.nio.ByteBuffer;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.teiid.common.buffer.impl.FileStoreCache.BlockInfo;
+
+/**
+ * Represents the logical structure of a cache group / directory
+ *
+ * Implemented by a closed hash table using a single step linear probe with delayed removal.
+ * Uses power of 2 hashing.
+ *
+ * Provides an extremely simple hash structure that rivals {@link HashMap} performance and
+ * is directly mapped to {@link ByteBuffer}s to avoid serialization overhead.
+ *
+ * Does not expect keys or values to be negative.
+ */
+public class BlockClosedLongIntHashTable {
+
+ private enum Mode {
+ GET,
+ UPDATE,
+ REMOVE
+ }
+
+ private static final int BYTES_PER_ROW = 12; //8+4
+ private static final int BLOCK_SIZE = FileStoreCache.BLOCK_DATA_BYTES/BYTES_PER_ROW;
+ private static final float LOAD_FACTOR = .7f;
+ private static final int MIN_SIZE = 1 << (31 - Integer.numberOfLeadingZeros(BLOCK_SIZE)); //should fit in a single block
+
+ static final int EMPTY = -1;
+ private static final int REMOVED = -2;
+
+ protected int size;
+ protected int capacityMask = EMPTY;
+ protected BlockManager blockManager;
+
+ public BlockClosedLongIntHashTable(BlockManager blockManager) {
+ this.blockManager = blockManager;
+ }
+
+ private void init(int capacity) {
+ int currentBlockCount = blockCount(capacityMask + 1);
+ int desiredBlockCount = blockCount(capacity);
+ if (capacity > capacityMask) {
+ for (int i = currentBlockCount; i < desiredBlockCount; i++) {
+ BlockInfo bb = blockManager.allocateBlock(i);
+ empty(bb.buf, BLOCK_SIZE);
+ blockManager.updateBlock(bb);
+ }
+ }
+ capacityMask = capacity - 1;
+ }
+
+ private void empty(ByteBuffer bb, int toIndex) {
+ bb.position(0);
+ for (int j = 0; j < toIndex; j++) {
+ bb.putLong(j * BYTES_PER_ROW, EMPTY);
+ }
+ }
+
+ private static int blockCount(int size) {
+ int currentBlockCount = (size) / BLOCK_SIZE;
+ if (size%BLOCK_SIZE > 0) {
+ currentBlockCount++;
+ }
+ return currentBlockCount;
+ }
+
+ public synchronized int put(long key, int value) {
+ int result = getOrUpdate(key, value, Mode.UPDATE);
+ if ((result == EMPTY || result == REMOVED) && ++size > LOAD_FACTOR*capacityMask) {
+ int newCapacity = (capacityMask+1)<<1;
+ int oldLength = capacityMask + 1;
+ init(newCapacity);
+ rehash(oldLength, newCapacity);
+ }
+ return result;
+ }
+
+ public synchronized int get(long key) {
+ return getOrUpdate(key, EMPTY, Mode.GET);
+ }
+
+ public synchronized int remove(long key) {
+ int result = getOrUpdate(key, EMPTY, Mode.REMOVE);
+ if (result != EMPTY && --size*LOAD_FACTOR < capacityMask>>3 && (capacityMask+1)>>1 >= MIN_SIZE) {
+ //reduce the size of the table by half
+ int oldLength = capacityMask + 1;
+ capacityMask >>= 1;
+ rehash(oldLength, oldLength>>1);
+ int oldBlocks = blockCount(oldLength);
+ int newBlocks = blockCount(capacityMask +1);
+ for (int i = oldBlocks-1; i >= newBlocks; i--) {
+ blockManager.freeBlock(i);
+ }
+ }
+ return result;
+ }
+
+ private void rehash(int oldLength, int newLength) {
+ BlockInfo lastBlockInfo = null;
+ ByteBuffer lastBlock = null;
+ for (int i = 0; i < oldLength; i++) {
+ int relativeIndex = i%BLOCK_SIZE;
+ if (lastBlock == null || relativeIndex == 0) {
+ int lastIndex = i/BLOCK_SIZE;
+ lastBlockInfo = blockManager.getBlock(lastIndex);
+ lastBlock = lastBlockInfo.buf;
+ if (i < newLength) {
+ byte[] buf = new byte[FileStoreCache.BLOCK_DATA_BYTES];
+ lastBlock.position(0);
+ lastBlock.get(buf);
+ ByteBuffer copyBlock = ByteBuffer.wrap(buf);
+ empty(lastBlock, Math.min(BLOCK_SIZE, oldLength - lastIndex*BLOCK_SIZE));
+ blockManager.updateBlock(lastBlockInfo);
+ lastBlock = copyBlock;
+ }
+ }
+ lastBlock.position(relativeIndex*BYTES_PER_ROW);
+ long oldKey = lastBlock.getLong();
+ int oldValue = lastBlock.getInt();
+ if (oldKey != REMOVED && oldKey != EMPTY) {
+ getOrUpdate(oldKey, oldValue, Mode.UPDATE);
+ }
+ }
+ }
+
+ @SuppressWarnings("null")
+ protected int getOrUpdate(long key, int value, Mode mode) {
+ if (capacityMask == EMPTY) {
+ if (mode == Mode.GET || mode == Mode.REMOVE) {
+ return EMPTY;
+ }
+ init(MIN_SIZE);
+ }
+ int i = hashIndex(key);
+ BlockInfo lastBlockInfo = null;
+ long old = EMPTY;
+ int position = 0;
+ while (true) {
+ int relativeIndex = i%BLOCK_SIZE;
+ if (lastBlockInfo == null || relativeIndex == 0) {
+ int index = i/BLOCK_SIZE;
+ lastBlockInfo = blockManager.getBlock(index);
+ }
+ position = relativeIndex*BYTES_PER_ROW;
+ old = lastBlockInfo.buf.getLong(position);
+ if (old == EMPTY || old == key || (mode == Mode.UPDATE && old == REMOVED)) {
+ break;
+ }
+ i = (i + 1) & capacityMask;
+ }
+ int result = EMPTY;
+ if (old != EMPTY && old != REMOVED) {
+ result = lastBlockInfo.buf.getInt(position + 8);
+ }
+ switch (mode) {
+ case GET:
+ return result;
+ case UPDATE:
+ lastBlockInfo.buf.putLong(position, key);
+ lastBlockInfo.buf.putInt(position + 8, value);
+ blockManager.updateBlock(lastBlockInfo);
+ return result;
+ case REMOVE:
+ if (old == EMPTY || old == REMOVED) {
+ return EMPTY;
+ }
+ lastBlockInfo.buf.putLong(position, REMOVED);
+ blockManager.updateBlock(lastBlockInfo);
+ return result;
+ default:
+ throw new AssertionError();
+ }
+ }
+
+ private int hashIndex(long key) {
+ //start with the usual long hash
+ int primaryHash = (int)(key ^ (key >>> 32));
+ //allow the lower bits to spread the entries
+ primaryHash += primaryHash <<= 2;
+ primaryHash += primaryHash <<= 3;
+ return primaryHash & capacityMask;
+ }
+
+ public synchronized int size() {
+ return size;
+ }
+
+ public synchronized Map<Long, Integer> remove() {
+ Map<Long, Integer> result = new HashMap<Long, Integer>();
+ BlockInfo lastBlockInfo = null;
+ int blockIndex = 0;
+ for (int i = capacityMask; i >= 0; i--) {
+ int relativeIndex = i%BLOCK_SIZE;
+ if (lastBlockInfo == null || relativeIndex == BLOCK_SIZE - 1) {
+ if (lastBlockInfo != null) {
+ blockManager.freeBlock(blockIndex);
+ }
+ blockIndex = i/BLOCK_SIZE;
+ lastBlockInfo = blockManager.getBlock(blockIndex);
+ }
+ lastBlockInfo.buf.position(relativeIndex*BYTES_PER_ROW);
+ long key = lastBlockInfo.buf.getLong();
+ if (key != EMPTY && key != REMOVED) {
+ result.put(key, lastBlockInfo.buf.getInt());
+ }
+ }
+ blockManager.free();
+ return result;
+ }
+
+}
Copied: branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/BlockManager.java (from rev 3506, trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockManager.java)
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/BlockManager.java (rev 0)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/BlockManager.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer.impl;
+
+import org.teiid.common.buffer.impl.FileStoreCache.BlockInfo;
+
+/**
+ * Represents an INode
+ *
+ * Returned BlockInfo may be shared. If shared there and no guarantees about position and mark.
+ * in particular system/index blocks can be used by multiple threads relative methods should be
+ * avoided, but may be used for exclusive write operations.
+ * Otherwise the position will be 0.
+ *
+ * Due to buffermanager locking, non-index data blocks can be assumed to be thread-safe.
+ */
+public interface BlockManager {
+
+ int getInode();
+
+ BlockInfo allocateBlock(int index);
+
+ BlockInfo getBlock(int index);
+
+ void updateBlock(BlockInfo block);
+
+ void freeBlock(int index);
+
+ void free();
+
+}
Modified: branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -22,27 +22,42 @@
package org.teiid.common.buffer.impl;
-import java.io.*;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
+import org.teiid.client.BatchSerializer;
import org.teiid.common.buffer.*;
-import org.teiid.common.buffer.BatchManager.ManagedBatch;
+import org.teiid.common.buffer.AutoCleanupUtil.Removable;
+import org.teiid.common.buffer.LobManager.ReferenceMode;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.types.DataTypeManager;
-import org.teiid.core.util.Assertion;
+import org.teiid.core.types.DataTypeManager.WeakReferenceHashedValueCache;
import org.teiid.dqp.internal.process.DQPConfiguration;
+import org.teiid.dqp.internal.process.SerializableTupleBatch;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.logging.MessageLevel;
@@ -57,341 +72,170 @@
* <p>Default implementation of BufferManager.</p>
* Responsible for creating/tracking TupleBuffers and providing access to the StorageManager.
* </p>
- * The buffering strategy attempts to purge batches from the least recently used TupleBuffer
- * from before (which wraps around circularly) the last used batch. This attempts to compensate
- * for our tendency to read buffers in a forward manner. If our processing algorithms are changed
- * to use alternating ascending/descending access, then the buffering approach could be replaced
- * with a simple LRU.
*
- * TODO: allow for cached stores to use lru - (result set/mat view)
- * TODO: account for row/content based sizing (difficult given value sharing)
- * TODO: account for memory based lobs (it would be nice if the approximate buffer size matched at 100kB)
* TODO: add detection of pinned batches to prevent unnecessary purging of non-persistent batches
* - this is not necessary for already persistent batches, since we hold a weak reference
*/
public class BufferManagerImpl implements BufferManager, StorageManager, ReplicatedObject {
- private static final int IO_BUFFER_SIZE = 1 << 14;
- private static final int COMPACTION_THRESHOLD = 1 << 25; //start checking at 32 megs
-
- private final class CleanupHook implements org.teiid.common.buffer.BatchManager.CleanupHook {
-
- private long id;
- private int beginRow;
- private WeakReference<BatchManagerImpl> ref;
-
- CleanupHook(long id, int beginRow, BatchManagerImpl batchManager) {
- this.id = id;
- this.beginRow = beginRow;
- this.ref = new WeakReference<BatchManagerImpl>(batchManager);
+ private final class BatchManagerImpl implements BatchManager, Serializer<List<? extends List<?>>> {
+ final Long id;
+ SizeUtility sizeUtility;
+ private WeakReference<BatchManagerImpl> ref = new WeakReference<BatchManagerImpl>(this);
+ AtomicBoolean prefersMemory = new AtomicBoolean();
+ String[] types;
+ private LobManager lobManager;
+
+ private BatchManagerImpl(Long newID, String[] types) {
+ this.id = newID;
+ this.sizeUtility = new SizeUtility(types);
+ this.types = types;
+ cache.createCacheGroup(newID);
}
- public void cleanup() {
- BatchManagerImpl batchManager = ref.get();
- if (batchManager == null) {
- return;
- }
- cleanupManagedBatch(batchManager, beginRow, id);
+ @Override
+ public Long getId() {
+ return id;
}
- }
-
- private final class BatchManagerImpl implements BatchManager {
- private final String id;
- private volatile FileStore store;
- private Map<Long, long[]> physicalMapping = new ConcurrentHashMap<Long, long[]>();
- private ReadWriteLock compactionLock = new ReentrantReadWriteLock();
- private AtomicLong unusedSpace = new AtomicLong();
- private int[] lobIndexes;
- private SizeUtility sizeUtility;
-
- private BatchManagerImpl(String newID, int[] lobIndexes) {
- this.id = newID;
- this.store = createFileStore(id);
- this.store.setCleanupReference(this);
- this.lobIndexes = lobIndexes;
- this.sizeUtility = new SizeUtility();
+ public void setLobManager(LobManager lobManager) {
+ this.lobManager = lobManager;
}
- public FileStore createStorage(String prefix) {
- return createFileStore(id+prefix);
- }
-
@Override
- public ManagedBatch createManagedBatch(TupleBatch batch, boolean softCache)
- throws TeiidComponentException {
- ManagedBatchImpl mbi = new ManagedBatchImpl(batch, this, softCache);
- mbi.addToCache(false);
- persistBatchReferences();
- return mbi;
+ public String[] getTypes() {
+ return types;
}
- private boolean shouldCompact(long offset) {
- return offset > COMPACTION_THRESHOLD && unusedSpace.get() * 4 > offset * 3;
+ @Override
+ public boolean prefersMemory() {
+ return prefersMemory.get();
}
- private long getOffset() throws TeiidComponentException {
- long offset = store.getLength();
- if (!shouldCompact(offset)) {
- return offset;
- }
- try {
- this.compactionLock.writeLock().lock();
- offset = store.getLength();
- //retest the condition to ensure that compaction is still needed
- if (!shouldCompact(offset)) {
- return offset;
- }
- FileStore newStore = createFileStore(id);
- newStore.setCleanupReference(this);
- byte[] buffer = new byte[IO_BUFFER_SIZE];
- List<long[]> values = new ArrayList<long[]>(physicalMapping.values());
- Collections.sort(values, new Comparator<long[]>() {
- @Override
- public int compare(long[] o1, long[] o2) {
- return Long.signum(o1[0] - o2[0]);
- }
- });
- for (long[] info : values) {
- long oldOffset = info[0];
- info[0] = newStore.getLength();
- int size = (int)info[1];
- while (size > 0) {
- int toWrite = Math.min(IO_BUFFER_SIZE, size);
- store.readFully(oldOffset, buffer, 0, toWrite);
- newStore.write(buffer, 0, toWrite);
- size -= toWrite;
- }
- }
- store.remove();
- store = newStore;
- long oldOffset = offset;
- offset = store.getLength();
- if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
- LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "Compacted store", id, "pre-size", oldOffset, "post-size", offset); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- return offset;
- } finally {
- this.compactionLock.writeLock().unlock();
- }
- }
-
@Override
- public void remove() {
- this.store.remove();
+ public void setPrefersMemory(boolean prefers) {
+ //TODO: it's only expected to move from not preferring to prefefring
+ this.prefersMemory.set(prefers);
}
- }
-
- /**
- * Holder for active batches
- */
- private class TupleBufferInfo {
- TreeMap<Integer, ManagedBatchImpl> batches = new TreeMap<Integer, ManagedBatchImpl>();
- Integer lastUsed = null;
- ManagedBatchImpl removeBatch(int row) {
- ManagedBatchImpl result = batches.remove(row);
- if (result != null) {
- activeBatchKB -= result.sizeEstimate;
- }
- return result;
+ @Override
+ public boolean useSoftCache() {
+ return prefersMemory.get();
}
- }
-
- private final class ManagedBatchImpl implements ManagedBatch {
- private boolean persistent;
- private boolean softCache;
- private volatile TupleBatch activeBatch;
- private volatile Reference<TupleBatch> batchReference;
- private int beginRow;
- private BatchManagerImpl batchManager;
- private long id;
- private LobManager lobManager;
- private int sizeEstimate;
- public ManagedBatchImpl(TupleBatch batch, BatchManagerImpl manager, boolean softCache) {
- this.softCache = softCache;
- id = batchAdded.incrementAndGet();
- this.activeBatch = batch;
- this.beginRow = batch.getBeginRow();
- this.batchManager = manager;
- if (this.batchManager.lobIndexes != null) {
- this.lobManager = new LobManager();
- }
- sizeEstimate = (int) Math.max(1, manager.sizeUtility.getBatchSize(batch) / 1024);
- if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
- LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "Add batch to BufferManager", id, "with size estimate", sizeEstimate); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ @Override
+ public Reference<? extends BatchManager> getBatchManagerReference() {
+ return ref;
}
@Override
- public void setPrefersMemory(boolean prefers) {
- this.softCache = prefers;
- //TODO: could recreate the reference
+ public Long createManagedBatch(List<? extends List<?>> batch)
+ throws TeiidComponentException {
+ int sizeEstimate = getSizeEstimate(batch);
+ Long oid = batchAdded.getAndIncrement();
+ CacheEntry ce = new CacheEntry(oid);
+ ce.setObject(batch);
+ ce.setSizeEstimate(sizeEstimate);
+ ce.setSerializer(this.ref);
+ return addCacheEntry(ce, this);
}
- private void addToCache(boolean update) {
- synchronized (activeBatches) {
- TupleBatch batch = this.activeBatch;
- if (batch == null) {
- return; //already removed
+ @Override
+ public List<? extends List<?>> deserialize(ObjectInputStream ois)
+ throws IOException, ClassNotFoundException {
+ List<? extends List<?>> batch = BatchSerializer.readBatch(ois, types);
+ if (lobManager != null) {
+ for (List<?> list : batch) {
+ try {
+ lobManager.updateReferences(list, ReferenceMode.ATTACH);
+ } catch (TeiidComponentException e) {
+ throw new TeiidRuntimeException(e);
+ }
}
- activeBatchKB += sizeEstimate;
- TupleBufferInfo tbi = null;
- if (update) {
- tbi = activeBatches.remove(batchManager.id);
- } else {
- tbi = activeBatches.get(batchManager.id);
- }
- if (tbi == null) {
- tbi = new TupleBufferInfo();
- update = true;
- }
- if (update) {
- activeBatches.put(batchManager.id, tbi);
- }
- Assertion.isNull(tbi.batches.put(this.beginRow, this));
}
+ return batch;
}
-
+
@Override
- public TupleBatch getBatch(boolean cache, String[] types) throws TeiidComponentException {
+ public void serialize(List<? extends List<?>> obj,
+ ObjectOutputStream oos) throws IOException {
+ //it's expected that the containing structure has updated the lob manager
+ BatchSerializer.writeBatch(oos, types, obj);
+ }
+
+ public int getSizeEstimate(List<? extends List<?>> obj) {
+ return (int) Math.max(1, sizeUtility.getBatchSize(obj) / 1024);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<List<?>> getBatch(Long batch, boolean retain)
+ throws TeiidComponentException {
+ cleanSoftReferences();
long reads = readAttempts.incrementAndGet();
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
- LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, batchManager.id, "getting batch", reads, "reference hits", referenceHit.get()); //$NON-NLS-1$ //$NON-NLS-2$
+ LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, id, "getting batch", batch, "total reads", reads, "reference hits", referenceHit.get()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- synchronized (activeBatches) {
- TupleBufferInfo tbi = activeBatches.remove(batchManager.id);
- if (tbi != null) {
- boolean put = true;
- if (!cache) {
- tbi.removeBatch(this.beginRow);
- if (tbi.batches.isEmpty()) {
- put = false;
- }
- }
- if (put) {
- tbi.lastUsed = this.beginRow;
- activeBatches.put(batchManager.id, tbi);
- }
- }
+ CacheEntry ce = fastGet(batch, prefersMemory.get(), retain);
+ if (ce != null) {
+ return (List<List<?>>)(!retain?ce.nullOut():ce.getObject());
}
- persistBatchReferences();
synchronized (this) {
- TupleBatch batch = this.activeBatch;
- if (batch != null){
- return batch;
+ ce = fastGet(batch, prefersMemory.get(), retain);
+ if (ce != null) {
+ return (List<List<?>>)(!retain?ce.nullOut():ce.getObject());
}
- Reference<TupleBatch> ref = this.batchReference;
- this.batchReference = null;
- if (ref != null) {
- batch = ref.get();
- if (batch != null) {
- if (cache) {
- this.activeBatch = batch;
- addToCache(true);
- }
- referenceHit.getAndIncrement();
- return batch;
- }
- }
long count = readCount.incrementAndGet();
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
- LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, batchManager.id, id, "reading batch from disk, total reads:", count); //$NON-NLS-1$
+ LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, id, id, "reading batch", batch, "from storage, total reads:", count); //$NON-NLS-1$ //$NON-NLS-2$
}
- try {
- this.batchManager.compactionLock.readLock().lock();
- long[] info = batchManager.physicalMapping.get(this.id);
- Assertion.isNotNull(info, "Invalid batch " + id); //$NON-NLS-1$
- ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(batchManager.store.createInputStream(info[0]), IO_BUFFER_SIZE));
- batch = new TupleBatch();
- batch.setDataTypes(types);
- batch.readExternal(ois);
- batch.setRowOffset(this.beginRow);
- batch.setDataTypes(null);
- if (lobManager != null) {
- for (List<?> tuple : batch.getTuples()) {
- lobManager.updateReferences(batchManager.lobIndexes, tuple);
- }
- }
- if (cache) {
- this.activeBatch = batch;
- addToCache(true);
- }
- return batch;
- } catch(IOException e) {
- throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", batchManager.id)); //$NON-NLS-1$
- } catch (ClassNotFoundException e) {
- throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", batchManager.id)); //$NON-NLS-1$
- } finally {
- this.batchManager.compactionLock.readLock().unlock();
- }
- }
- }
-
- public synchronized void persist() throws TeiidComponentException {
- boolean lockheld = false;
- try {
- TupleBatch batch = activeBatch;
- if (batch != null) {
- if (!persistent) {
- long count = writeCount.incrementAndGet();
- if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
- LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, batchManager.id, id, "writing batch to disk, total writes: ", count); //$NON-NLS-1$
- }
- long offset = 0;
- if (lobManager != null) {
- for (List<?> tuple : batch.getTuples()) {
- lobManager.updateReferences(batchManager.lobIndexes, tuple);
- }
- }
- synchronized (batchManager.store) {
- offset = batchManager.getOffset();
- OutputStream fsos = new BufferedOutputStream(batchManager.store.createOutputStream(), IO_BUFFER_SIZE);
- ObjectOutputStream oos = new ObjectOutputStream(fsos);
- batch.writeExternal(oos);
- oos.close();
- long size = batchManager.store.getLength() - offset;
- long[] info = new long[] {offset, size};
- batchManager.physicalMapping.put(this.id, info);
- }
- if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
- LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, batchManager.id, id, "batch written starting at:", offset); //$NON-NLS-1$
- }
- }
- if (softCache) {
- this.batchReference = new SoftReference<TupleBatch>(batch);
- } else if (useWeakReferences) {
- this.batchReference = new WeakReference<TupleBatch>(batch);
- }
+ ce = cache.get(batch, this);
+ if (ce == null) {
+ throw new AssertionError("Batch not found in storage " + batch); //$NON-NLS-1$
}
- } catch (IOException e) {
- throw new TeiidComponentException(e);
- } catch (Throwable e) {
- throw new TeiidComponentException(e);
- } finally {
- persistent = true;
- activeBatch = null;
- if (lockheld) {
- this.batchManager.compactionLock.writeLock().unlock();
+ if (!retain) {
+ cache.remove(this.id, batch);
}
- }
+ ce.setSerializer(this.ref);
+ if (retain) {
+ addMemoryEntry(ce);
+ }
+ }
+ return (List<List<?>>)ce.getObject();
}
+
+ @Override
+ public void remove(Long batch) {
+ cleanSoftReferences();
+ BufferManagerImpl.this.remove(id, batch, prefersMemory.get());
+ }
+ @Override
public void remove() {
- cleanupManagedBatch(batchManager, beginRow, id);
+ removeCacheGroup(id, prefersMemory.get());
}
-
+
@Override
- public CleanupHook getCleanupHook() {
- return new CleanupHook(id, beginRow, batchManager);
+ public String toString() {
+ return id.toString();
}
+ }
+
+ private static class BatchSoftReference extends SoftReference<CacheEntry> {
+
+ private int sizeEstimate;
+ private Long key;
- @Override
- public String toString() {
- return "ManagedBatch " + batchManager.id + " " + this.beginRow + " " + activeBatch; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ public BatchSoftReference(CacheEntry referent,
+ ReferenceQueue<? super CacheEntry> q, int sizeEstimate) {
+ super(referent, q);
+ this.sizeEstimate = sizeEstimate;
+ this.key = referent.getId();
}
}
+
+ private static final int TARGET_BYTES_PER_ROW = 1 << 11; //2k bytes per row
+ private static ReferenceQueue<CacheEntry> SOFT_QUEUE = new ReferenceQueue<CacheEntry>();
// Configuration
private int connectorBatchSize = BufferManager.DEFAULT_CONNECTOR_BATCH_SIZE;
@@ -399,21 +243,44 @@
//set to acceptable defaults for testing
private int maxProcessingKB = 1 << 11;
private Integer maxProcessingKBOrig;
- private int maxReserveKB = 1 << 25;
+ private AtomicInteger maxReserveKB = new AtomicInteger(1 << 18);
private volatile int reserveBatchKB;
private int maxActivePlans = DQPConfiguration.DEFAULT_MAX_ACTIVE_PLANS; //used as a hint to set the reserveBatchKB
private boolean useWeakReferences = true;
+ private boolean inlineLobs = true;
+ private int targetBytesPerRow = TARGET_BYTES_PER_ROW;
+ private int maxSoftReferences;
private ReentrantLock lock = new ReentrantLock(true);
private Condition batchesFreed = lock.newCondition();
- private volatile int activeBatchKB = 0;
- private Map<String, TupleBufferInfo> activeBatches = new LinkedHashMap<String, TupleBufferInfo>();
+ private AtomicInteger activeBatchKB = new AtomicInteger();
+
+ //tiered memory entries. the first tier is just a queue of adds/gets. once accessed again, the entry moves to the tenured tier.
+ private LinkedHashMap<Long, CacheEntry> memoryEntries = new LinkedHashMap<Long, CacheEntry>(16, .75f, false);
+ private LinkedHashMap<Long, CacheEntry> tenuredMemoryEntries = new LinkedHashMap<Long, CacheEntry>(16, .75f, true);
+
+ //limited size reference caches based upon the memory settings
+ private WeakReferenceHashedValueCache<CacheEntry> weakReferenceCache;
+ private Map<Long, BatchSoftReference> softCache = Collections.synchronizedMap(new LinkedHashMap<Long, BatchSoftReference>(16, .75f, false) {
+ private static final long serialVersionUID = 1L;
+
+ protected boolean removeEldestEntry(Map.Entry<Long,BatchSoftReference> eldest) {
+ if (size() > maxSoftReferences) {
+ BatchSoftReference bsr = eldest.getValue();
+ maxReserveKB.addAndGet(bsr.sizeEstimate);
+ bsr.clear();
+ return true;
+ }
+ return false;
+ };
+ });
+
+ Cache cache;
+
private Map<String, TupleReference> tupleBufferMap = new ConcurrentHashMap<String, TupleReference>();
private ReferenceQueue<TupleBuffer> tupleBufferQueue = new ReferenceQueue<TupleBuffer>();
- private StorageManager diskMgr;
-
private AtomicLong tsId = new AtomicLong();
private AtomicLong batchAdded = new AtomicLong();
private AtomicLong readCount = new AtomicLong();
@@ -463,58 +330,51 @@
public void setConnectorBatchSize(int connectorBatchSize) {
this.connectorBatchSize = connectorBatchSize;
}
+
+ public void setTargetBytesPerRow(int targetBytesPerRow) {
+ this.targetBytesPerRow = targetBytesPerRow;
+ }
public void setProcessorBatchSize(int processorBatchSize) {
this.processorBatchSize = processorBatchSize;
}
- /**
- * Add a storage manager to this buffer manager, order is unimportant
- * @param storageManager Storage manager to add
- */
- public void setStorageManager(StorageManager storageManager) {
- Assertion.isNotNull(storageManager);
- Assertion.isNull(diskMgr);
- this.diskMgr = storageManager;
- }
-
- public StorageManager getStorageManager() {
- return diskMgr;
- }
-
@Override
public TupleBuffer createTupleBuffer(final List elements, String groupName,
TupleSourceType tupleSourceType) {
- final String newID = String.valueOf(this.tsId.getAndIncrement());
+ final Long newID = this.tsId.getAndIncrement();
int[] lobIndexes = LobManager.getLobIndexes(elements);
- BatchManager batchManager = new BatchManagerImpl(newID, lobIndexes);
- TupleBuffer tupleBuffer = new TupleBuffer(batchManager, newID, elements, lobIndexes, getProcessorBatchSize());
+ String[] types = TupleBuffer.getTypeNames(elements);
+ BatchManagerImpl batchManager = createBatchManager(newID, types);
+ LobManager lobManager = null;
+ FileStore lobStore = null;
+ if (lobIndexes != null) {
+ lobStore = createFileStore(newID + "_lobs"); //$NON-NLS-1$
+ lobManager = new LobManager(lobIndexes, lobStore);
+ batchManager.setLobManager(lobManager);
+ }
+ TupleBuffer tupleBuffer = new TupleBuffer(batchManager, String.valueOf(newID), elements, lobManager, getProcessorBatchSize(elements));
+ if (lobStore != null) {
+ AutoCleanupUtil.setCleanupReference(batchManager, lobStore);
+ }
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
- LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Creating TupleBuffer:", newID, elements, Arrays.toString(tupleBuffer.getTypes()), "of type", tupleSourceType); //$NON-NLS-1$ //$NON-NLS-2$
+ LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Creating TupleBuffer:", newID, elements, Arrays.toString(types), "of type", tupleSourceType); //$NON-NLS-1$ //$NON-NLS-2$
}
+ tupleBuffer.setInlineLobs(inlineLobs);
return tupleBuffer;
}
- private void cleanupManagedBatch(BatchManagerImpl batchManager, int beginRow, long id) {
- synchronized (activeBatches) {
- TupleBufferInfo tbi = activeBatches.get(batchManager.id);
- if (tbi != null && tbi.removeBatch(beginRow) != null) {
- if (tbi.batches.isEmpty()) {
- activeBatches.remove(batchManager.id);
- }
- }
- }
- long[] info = batchManager.physicalMapping.remove(id);
- if (info != null) {
- batchManager.unusedSpace.addAndGet(info[1]);
- }
- }
-
public STree createSTree(final List elements, String groupName, int keyLength) {
- String newID = String.valueOf(this.tsId.getAndIncrement());
+ Long newID = this.tsId.getAndIncrement();
int[] lobIndexes = LobManager.getLobIndexes(elements);
- BatchManager bm = new BatchManagerImpl(newID, lobIndexes);
- BatchManager keyManager = new BatchManagerImpl(String.valueOf(this.tsId.getAndIncrement()), null);
+ String[] types = TupleBuffer.getTypeNames(elements);
+ BatchManagerImpl bm = createBatchManager(newID, types);
+ LobManager lobManager = null;
+ if (lobIndexes != null) {
+ lobManager = new LobManager(lobIndexes, null); //persistence is not expected yet - later we might utilize storage for out-of-line lob values
+ bm.setLobManager(lobManager);
+ }
+ BatchManager keyManager = createBatchManager(this.tsId.getAndIncrement(), Arrays.copyOf(types, keyLength));
int[] compareIndexes = new int[keyLength];
for (int i = 1; i < compareIndexes.length; i++) {
compareIndexes[i] = i;
@@ -522,16 +382,33 @@
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Creating STree:", newID); //$NON-NLS-1$
}
- return new STree(keyManager, bm, new ListNestedSortComparator(compareIndexes), getProcessorBatchSize(), keyLength, TupleBuffer.getTypeNames(elements));
+ return new STree(keyManager, bm, new ListNestedSortComparator(compareIndexes), getProcessorBatchSize(elements), getProcessorBatchSize(elements.subList(0, keyLength)), keyLength, lobManager);
}
+ private BatchManagerImpl createBatchManager(final Long newID, String[] types) {
+ BatchManagerImpl bm = new BatchManagerImpl(newID, types);
+ final AtomicBoolean prefersMemory = bm.prefersMemory;
+ AutoCleanupUtil.setCleanupReference(bm, new Removable() {
+
+ @Override
+ public void remove() {
+ BufferManagerImpl.this.removeCacheGroup(newID, prefersMemory.get());
+ }
+ });
+ return bm;
+ }
+
@Override
public FileStore createFileStore(String name) {
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Creating FileStore:", name); //$NON-NLS-1$
}
- return this.diskMgr.createFileStore(name);
+ return this.cache.createFileStore(name);
}
+
+ public Cache getCache() {
+ return cache;
+ }
public void setMaxActivePlans(int maxActivePlans) {
this.maxActivePlans = maxActivePlans;
@@ -542,23 +419,23 @@
}
public void setMaxReserveKB(int maxReserveBatchKB) {
- this.maxReserveKB = maxReserveBatchKB;
+ this.maxReserveKB.set(maxReserveBatchKB);
}
@Override
public void initialize() throws TeiidComponentException {
int maxMemory = (int)Math.min(Runtime.getRuntime().maxMemory() / 1024, Integer.MAX_VALUE);
maxMemory -= 300 * 1024; //assume 300 megs of overhead for the AS/system stuff
- if (maxReserveKB < 0) {
- this.maxReserveKB = 0;
+ if (getMaxReserveKB() < 0) {
+ this.setMaxReserveKB(0);
int one_gig = 1024 * 1024;
if (maxMemory > one_gig) {
//assume 75% of the memory over the first gig
- this.maxReserveKB += (int)Math.max(0, (maxMemory - one_gig) * .75);
+ this.maxReserveKB.addAndGet(((int)Math.max(0, (maxMemory - one_gig) * .75)));
}
- this.maxReserveKB += Math.max(0, Math.min(one_gig, maxMemory) * .5);
+ this.maxReserveKB.addAndGet(((int)Math.max(0, Math.min(one_gig, maxMemory) * .5)));
}
- this.reserveBatchKB = this.maxReserveKB;
+ this.reserveBatchKB = this.getMaxReserveKB();
if (this.maxProcessingKBOrig == null) {
//store the config value so that we can be reinitialized (this is not a clean approach)
this.maxProcessingKBOrig = this.maxProcessingKB;
@@ -566,6 +443,12 @@
if (this.maxProcessingKBOrig < 0) {
this.maxProcessingKB = Math.max(Math.min(8 * processorBatchSize, Integer.MAX_VALUE), (int)(.1 * maxMemory)/maxActivePlans);
}
+ int memoryBatches = (this.maxProcessingKB * maxActivePlans + this.getMaxReserveKB()) / (processorBatchSize * targetBytesPerRow / 1024);
+ int logSize = 39 - Integer.numberOfLeadingZeros(memoryBatches);
+ if (useWeakReferences) {
+ weakReferenceCache = new WeakReferenceHashedValueCache<CacheEntry>(Math.min(20, logSize));
+ }
+ this.maxSoftReferences = 1 << Math.max(28, logSize+2);
}
@Override
@@ -594,7 +477,7 @@
try {
if (mode == BufferReserveMode.WAIT) {
//don't wait for more than is available
- int waitCount = Math.min(count, this.maxReserveKB);
+ int waitCount = Math.min(count, this.getMaxReserveKB());
while (waitCount > 0 && waitCount > this.reserveBatchKB) {
try {
batchesFreed.await(100, TimeUnit.MILLISECONDS);
@@ -618,60 +501,233 @@
}
void persistBatchReferences() {
- if (activeBatchKB == 0 || activeBatchKB <= reserveBatchKB) {
- int memoryCount = activeBatchKB + maxReserveKB - reserveBatchKB;
+ if (activeBatchKB.get() == 0 || activeBatchKB.get() <= reserveBatchKB) {
+ int memoryCount = activeBatchKB.get() + getMaxReserveKB() - reserveBatchKB;
if (DataTypeManager.isValueCacheEnabled()) {
- if (memoryCount < maxReserveKB / 8) {
+ if (memoryCount < getMaxReserveKB() / 8) {
DataTypeManager.setValueCacheEnabled(false);
}
- } else if (memoryCount > maxReserveKB / 4) {
+ } else if (memoryCount > getMaxReserveKB() / 4) {
DataTypeManager.setValueCacheEnabled(true);
}
return;
}
+ boolean first = true;
while (true) {
- ManagedBatchImpl mb = null;
- synchronized (activeBatches) {
- if (activeBatchKB == 0 || activeBatchKB < reserveBatchKB * .8) {
+ CacheEntry ce = null;
+ synchronized (memoryEntries) {
+ if (activeBatchKB.get() == 0 || activeBatchKB.get() < reserveBatchKB * .8) {
break;
}
- Iterator<TupleBufferInfo> iter = activeBatches.values().iterator();
- TupleBufferInfo tbi = iter.next();
- Map.Entry<Integer, ManagedBatchImpl> entry = null;
- if (tbi.lastUsed != null) {
- entry = tbi.batches.floorEntry(tbi.lastUsed - 1);
+ if (first) { //let one entry per persist cycle loose its tenure. this helps us be more write avoident.
+ first = false;
+ if (!tenuredMemoryEntries.isEmpty()) {
+ Iterator<Map.Entry<Long, CacheEntry>> iter = tenuredMemoryEntries.entrySet().iterator();
+ Map.Entry<Long, CacheEntry> entry = iter.next();
+ iter.remove();
+ memoryEntries.put(entry.getKey(), entry.getValue());
+ }
}
- if (entry == null) {
- entry = tbi.batches.lastEntry();
+ LinkedHashMap<Long, CacheEntry> toDrain = memoryEntries;
+ if (memoryEntries.isEmpty()) {
+ toDrain = tenuredMemoryEntries;
+ if (tenuredMemoryEntries.isEmpty()) {
+ break;
+ }
+ }
+ Iterator<CacheEntry> iter = toDrain.values().iterator();
+ ce = iter.next();
+ iter.remove();
+ activeBatchKB.addAndGet(-ce.getSizeEstimate());
+ }
+ persist(ce);
+ }
+ }
+
+ void persist(CacheEntry ce) {
+ Serializer<?> s = ce.getSerializer().get();
+ if (s == null) {
+ return;
+ }
+ if (!ce.isPersistent()) {
+ long count = writeCount.incrementAndGet();
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
+ LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, ce.getId(), "writing batch to storage, total writes: ", count); //$NON-NLS-1$
+ }
+ cache.add(ce, s);
+ ce.setPersistent(true);
+ }
+ if (s.useSoftCache()) {
+ createSoftReference(ce);
+ } else if (useWeakReferences) {
+ weakReferenceCache.getValue(ce); //a get will set the value
+ }
+ }
+
+ private void createSoftReference(CacheEntry ce) {
+ BatchSoftReference ref = new BatchSoftReference(ce, SOFT_QUEUE, ce.getSizeEstimate()/2);
+ softCache.put(ce.getId(), ref);
+ maxReserveKB.addAndGet(- ce.getSizeEstimate()/2);
+ }
+
+ /**
+ * Get a CacheEntry without hitting the cache
+ */
+ CacheEntry fastGet(Long batch, boolean prefersMemory, boolean retain) {
+ CacheEntry ce = null;
+ synchronized (memoryEntries) {
+ if (retain) {
+ ce = tenuredMemoryEntries.get(batch);
+ if (ce == null) {
+ ce = memoryEntries.remove(batch);
+ if (ce != null) {
+ tenuredMemoryEntries.put(batch, ce);
+ }
}
- tbi.removeBatch(entry.getKey());
- if (tbi.batches.isEmpty()) {
- iter.remove();
+ } else {
+ ce = tenuredMemoryEntries.remove(batch);
+ if (ce == null) {
+ ce = memoryEntries.remove(batch);
}
- mb = entry.getValue();
}
- try {
- mb.persist();
- } catch (TeiidComponentException e) {
- LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, e, "Error persisting batch, attempts to read that batch later will result in an exception"); //$NON-NLS-1$
+ }
+ if (ce != null) {
+ if (!retain) {
+ BufferManagerImpl.this.remove(ce, true);
}
+ return ce;
}
+ if (prefersMemory) {
+ BatchSoftReference bsr = softCache.remove(batch);
+ if (bsr != null) {
+ ce = bsr.get();
+ if (ce != null) {
+ maxReserveKB.addAndGet(bsr.sizeEstimate);
+ }
+ }
+ } else if (useWeakReferences) {
+ ce = weakReferenceCache.getByHash(batch);
+ if (ce == null || !ce.getId().equals(batch)) {
+ return null;
+ }
+ }
+ if (ce != null && ce.getObject() != null) {
+ referenceHit.getAndIncrement();
+ if (retain) {
+ addMemoryEntry(ce);
+ } else {
+ BufferManagerImpl.this.remove(ce, false);
+ }
+ return ce;
+ }
+ return null;
}
+ void remove(Long gid, Long batch, boolean prefersMemory) {
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
+ LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "Removing batch from BufferManager", batch); //$NON-NLS-1$
+ }
+ CacheEntry ce = fastGet(batch, prefersMemory, false);
+ if (ce == null) {
+ cache.remove(gid, batch);
+ } else {
+ ce.nullOut();
+ }
+ }
+
+ private void remove(CacheEntry ce, boolean inMemory) {
+ if (inMemory) {
+ activeBatchKB.addAndGet(-ce.getSizeEstimate());
+ }
+ Serializer<?> s = ce.getSerializer().get();
+ if (s != null) {
+ cache.remove(s.getId(), ce.getId());
+ }
+ }
+
+ Long addCacheEntry(CacheEntry ce, Serializer<?> s) {
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
+ LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "Add batch to BufferManager", ce.getId(), "with size estimate", ce.getSizeEstimate()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ cache.addToCacheGroup(s.getId(), ce.getId());
+ addMemoryEntry(ce);
+ return ce.getId();
+ }
+
+ void addMemoryEntry(CacheEntry ce) {
+ persistBatchReferences();
+ synchronized (memoryEntries) {
+ memoryEntries.put(ce.getId(), ce);
+ }
+ activeBatchKB.getAndAdd(ce.getSizeEstimate());
+ }
+
+ void removeCacheGroup(Long id, boolean prefersMemory) {
+ cleanSoftReferences();
+ Collection<Long> vals = cache.removeCacheGroup(id);
+ for (Long val : vals) {
+ fastGet(val, prefersMemory, false);
+ }
+ }
+
+ void cleanSoftReferences() {
+ for (int i = 0; i < 10; i++) {
+ BatchSoftReference ref = (BatchSoftReference)SOFT_QUEUE.poll();
+ if (ref == null) {
+ break;
+ }
+ softCache.remove(ref.key);
+ maxReserveKB.addAndGet(ref.sizeEstimate);
+ ref.clear();
+ }
+ }
+
@Override
- public int getSchemaSize(List<? extends Expression> elements) {
+ public int getProcessorBatchSize(List<? extends Expression> schema) {
+ return getSizeEstimates(schema)[0];
+ }
+
+ private int[] getSizeEstimates(List<? extends Expression> elements) {
int total = 0;
boolean isValueCacheEnabled = DataTypeManager.isValueCacheEnabled();
- //we make a assumption that the average column size under 64bits is approximately 128bytes
- //this includes alignment, row/array, and reference overhead
for (Expression element : elements) {
Class<?> type = element.getType();
total += SizeUtility.getSize(isValueCacheEnabled, type);
}
+ //assume 64-bit
total += 8*elements.size() + 36; // column list / row overhead
- total *= processorBatchSize;
- return Math.max(1, total / 1024);
+
+ //nominal targetBytesPerRow but can scale up or down
+
+ int totalCopy = total;
+ boolean less = totalCopy < targetBytesPerRow;
+ int rowCount = processorBatchSize;
+
+ for (int i = 0; i < 3; i++) {
+ if (less) {
+ totalCopy <<= 1;
+ } else {
+ totalCopy >>= 2;
+ }
+ if (less && totalCopy > targetBytesPerRow
+ || !less && totalCopy < targetBytesPerRow) {
+ break;
+ }
+ if (less) {
+ rowCount <<= 1;
+ } else {
+ rowCount >>= 1;
+ }
+ }
+ rowCount = Math.max(1, rowCount);
+ total *= rowCount;
+ return new int[]{rowCount, Math.max(1, total / 1024)};
}
+
+ @Override
+ public int getSchemaSize(List<? extends Expression> elements) {
+ return getSizeEstimates(elements)[1];
+ }
public void shutdown() {
}
@@ -758,11 +814,9 @@
out.writeInt(buffer.getRowCount());
out.writeInt(buffer.getBatchSize());
out.writeObject(buffer.getTypes());
- out.writeBoolean(buffer.isPrefersMemory());
for (int row = 1; row <= buffer.getRowCount(); row+=buffer.getBatchSize()) {
TupleBatch b = buffer.getBatch(row);
- b.preserveTypes();
- out.writeObject(b);
+ out.writeObject(new SerializableTupleBatch(b, buffer.getTypes()));
}
}
@@ -812,7 +866,6 @@
int rowCount = in.readInt();
int batchSize = in.readInt();
String[] types = (String[])in.readObject();
- boolean prefersMemory = in.readBoolean();
List<ElementSymbol> schema = new ArrayList<ElementSymbol>(types.length);
for (String type : types) {
@@ -823,7 +876,6 @@
TupleBuffer buffer = createTupleBuffer(schema, "cached", TupleSourceType.FINAL); //$NON-NLS-1$
buffer.setBatchSize(batchSize);
buffer.setId(state_id);
- buffer.setPrefersMemory(prefersMemory);
for (int row = 1; row <= rowCount; row+=batchSize) {
TupleBatch batch = (TupleBatch)in.readObject();
@@ -844,4 +896,16 @@
@Override
public void droppedMembers(Collection<Serializable> addresses) {
}
+
+ public void setInlineLobs(boolean inlineLobs) {
+ this.inlineLobs = inlineLobs;
+ }
+
+ private int getMaxReserveKB() {
+ return maxReserveKB.get();
+ }
+
+ public void setCache(Cache cache) {
+ this.cache = cache;
+ }
}
Copied: branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/ExtensibleBufferedOutputStream.java (from rev 3506, trunk/engine/src/main/java/org/teiid/common/buffer/impl/ExtensibleBufferedOutputStream.java)
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/ExtensibleBufferedOutputStream.java (rev 0)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/ExtensibleBufferedOutputStream.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer.impl;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+
+public abstract class ExtensibleBufferedOutputStream extends OutputStream {
+
+ protected ByteBuffer buf;
+
+ public ExtensibleBufferedOutputStream() {
+ }
+
+ public void write(int b) throws IOException {
+ ensureBuffer();
+ if (buf.remaining() == 0) {
+ flush();
+ }
+ buf.put((byte)b);
+ }
+
+ private void ensureBuffer() {
+ if (buf == null) {
+ buf = newBuffer();
+ }
+ }
+
+ public void write(byte b[], int off, int len) throws IOException {
+ while (true) {
+ ensureBuffer();
+ int toCopy = Math.min(buf.remaining(), len);
+ buf.put(b, off, toCopy);
+ len -= toCopy;
+ off += toCopy;
+ if (buf.remaining() > 0) {
+ break;
+ }
+ flush();
+ }
+ }
+
+ public void flush() throws IOException {
+ if (buf != null && buf.position() > 0) {
+ flushDirect();
+ }
+ buf = null;
+ }
+
+ protected abstract ByteBuffer newBuffer();
+
+ protected abstract void flushDirect() throws IOException;
+
+ @Override
+ public void close() throws IOException {
+ flush();
+ }
+
+}
Modified: branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/FileStorageManager.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/FileStorageManager.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/FileStorageManager.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -29,13 +29,11 @@
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
-import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicLong;
import org.teiid.common.buffer.FileStore;
import org.teiid.common.buffer.StorageManager;
import org.teiid.core.TeiidComponentException;
-import org.teiid.core.util.Assertion;
import org.teiid.logging.LogManager;
import org.teiid.logging.MessageLevel;
import org.teiid.query.QueryPlugin;
@@ -47,7 +45,6 @@
public class FileStorageManager implements StorageManager {
public static final int DEFAULT_MAX_OPEN_FILES = 64;
- public static final long DEFAULT_MAX_FILESIZE = 2L * 1024L;
public static final long DEFAULT_MAX_BUFFERSPACE = 50L * 1024L * 1024L * 1024L;
private static final String FILE_PREFIX = "b_"; //$NON-NLS-1$
@@ -97,87 +94,85 @@
public class DiskStore extends FileStore {
private String name;
- private TreeMap<Long, FileInfo> storageFiles = new TreeMap<Long, FileInfo>();
+ private FileInfo fileInfo;
public DiskStore(String name) {
this.name = name;
}
- /**
- * Concurrent reads are possible, but only after writing is complete.
- */
- public int readDirect(long fileOffset, byte[] b, int offSet, int length) throws TeiidComponentException {
- Map.Entry<Long, FileInfo> entry = storageFiles.floorEntry(fileOffset);
- Assertion.isNotNull(entry);
- FileInfo fileInfo = entry.getValue();
- synchronized (fileInfo) {
+ @Override
+ public synchronized long getLength() {
+ if (fileInfo == null) {
+ return 0;
+ }
+ return fileInfo.file.length();
+ }
+
+ @Override
+ protected synchronized int readWrite(long fileOffset, byte[] b, int offSet,
+ int length, boolean write) throws IOException {
+ if (!write) {
try {
RandomAccessFile fileAccess = fileInfo.open();
- fileAccess.seek(fileOffset - entry.getKey());
+ fileAccess.seek(fileOffset);
return fileAccess.read(b, offSet, length);
- } catch (IOException e) {
- throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", fileInfo.file.getAbsoluteFile())); //$NON-NLS-1$
} finally {
fileInfo.close();
}
- }
- }
-
- /**
- * Concurrent writes are prevented by FileStore, but in general should not happen since processing is single threaded.
- */
- public void writeDirect(byte[] bytes, int offset, int length) throws TeiidComponentException {
- long used = usedBufferSpace.addAndGet(length);
- if (used > maxBufferSpace) {
- usedBufferSpace.addAndGet(-length);
- throw new TeiidComponentException(QueryPlugin.Util.getString("FileStoreageManager.space_exhausted", maxBufferSpace)); //$NON-NLS-1$
- }
- Map.Entry<Long, FileInfo> entry = this.storageFiles.lastEntry();
- boolean createNew = false;
- FileInfo fileInfo = null;
- long fileOffset = 0;
- if (entry == null) {
- createNew = true;
- } else {
- fileInfo = entry.getValue();
- fileOffset = entry.getKey();
- createNew = entry.getValue().file.length() + length > getMaxFileSize();
- }
- if (createNew) {
- FileInfo newFileInfo = new FileInfo(createFile(name, storageFiles.size()));
- if (fileInfo != null) {
- fileOffset += fileInfo.file.length();
+ }
+ if (fileInfo == null) {
+ fileInfo = new FileInfo(createFile(name));
+ }
+ long bytesUsed = 0;
+ try {
+ RandomAccessFile fileAccess = fileInfo.open();
+ long newLength = fileOffset + length;
+ bytesUsed = newLength - fileAccess.length();
+ if (bytesUsed > 0) {
+ long used = usedBufferSpace.addAndGet(bytesUsed);
+ if (used > maxBufferSpace) {
+ usedBufferSpace.addAndGet(-bytesUsed);
+ //TODO: trigger a compaction before this is thrown
+ throw new IOException(QueryPlugin.Util.getString("FileStoreageManager.space_exhausted", maxBufferSpace)); //$NON-NLS-1$
+ }
+ fileAccess.setLength(bytesUsed);
+ bytesUsed = 0;
}
- storageFiles.put(fileOffset, newFileInfo);
- fileInfo = newFileInfo;
+ fileAccess.seek(fileOffset);
+ fileAccess.write(b, offSet, length);
+ } finally {
+ if (bytesUsed > 0) {
+ usedBufferSpace.addAndGet(-bytesUsed);
+ }
+ fileInfo.close();
+ }
+ return length;
+ }
+
+ @Override
+ public synchronized void setLength(long length) throws IOException {
+ if (fileInfo == null) {
+ fileInfo = new FileInfo(createFile(name));
}
- synchronized (fileInfo) {
- try {
- RandomAccessFile fileAccess = fileInfo.open();
- long pointer = fileAccess.length();
- fileAccess.setLength(pointer + length);
- fileAccess.seek(pointer);
- fileAccess.write(bytes, offset, length);
- } catch(IOException e) {
- throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", fileInfo.file.getAbsoluteFile())); //$NON-NLS-1$
- } finally {
- fileInfo.close();
- }
- }
- }
+ try {
+ fileInfo.open().setLength(length);
+ } finally {
+ fileInfo.close();
+ }
+ }
+ @Override
public synchronized void removeDirect() {
- usedBufferSpace.addAndGet(-len);
- for (FileInfo info : storageFiles.values()) {
- info.delete();
+ usedBufferSpace.addAndGet(-getLength());
+ if (fileInfo != null){
+ fileInfo.delete();
}
}
-
+
}
// Initialization
private int maxOpenFiles = DEFAULT_MAX_OPEN_FILES;
- private long maxFileSize = DEFAULT_MAX_FILESIZE * 1024L * 1024L; // 2GB
private String directory;
private File dirFile;
@@ -216,14 +211,6 @@
}
}
- public void setMaxFileSize(long maxFileSize) {
- this.maxFileSize = maxFileSize * 1024L * 1024L;
- }
-
- void setMaxFileSizeDirect(long maxFileSize) {
- this.maxFileSize = maxFileSize;
- }
-
public void setMaxOpenFiles(int maxOpenFiles) {
this.maxOpenFiles = maxOpenFiles;
}
@@ -232,26 +219,18 @@
this.directory = directory;
}
- File createFile(String name, int fileNumber) throws TeiidComponentException {
- try {
- File storageFile = File.createTempFile(FILE_PREFIX + name + "_" + String.valueOf(fileNumber) + "_", null, this.dirFile); //$NON-NLS-1$ //$NON-NLS-2$
- if (LogManager.isMessageToBeRecorded(org.teiid.logging.LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
- LogManager.logDetail(org.teiid.logging.LogConstants.CTX_BUFFER_MGR, "Created temporary storage area file " + storageFile.getAbsoluteFile()); //$NON-NLS-1$
- }
- return storageFile;
- } catch(IOException e) {
- throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_creating", name + "_" + fileNumber)); //$NON-NLS-1$ //$NON-NLS-2$
+ File createFile(String name) throws IOException {
+ File storageFile = File.createTempFile(FILE_PREFIX + name + "_", null, this.dirFile); //$NON-NLS-1$
+ if (LogManager.isMessageToBeRecorded(org.teiid.logging.LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
+ LogManager.logDetail(org.teiid.logging.LogConstants.CTX_BUFFER_MGR, "Created temporary storage area file " + storageFile.getAbsoluteFile()); //$NON-NLS-1$
}
+ return storageFile;
}
public FileStore createFileStore(String name) {
return new DiskStore(name);
}
- public long getMaxFileSize() {
- return maxFileSize;
- }
-
public String getDirectory() {
return directory;
}
Copied: branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/FileStoreCache.java (from rev 3506, trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStoreCache.java)
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/FileStoreCache.java (rev 0)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/FileStoreCache.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -0,0 +1,746 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.teiid.common.buffer.Cache;
+import org.teiid.common.buffer.CacheEntry;
+import org.teiid.common.buffer.FileStore;
+import org.teiid.common.buffer.Serializer;
+import org.teiid.common.buffer.StorageManager;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidRuntimeException;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
+import org.teiid.logging.MessageLevel;
+import org.teiid.query.QueryPlugin;
+
+/**
+ * Implements storage against a {@link FileStore} abstraction using a filesystem paradigm.
+ * The filesystem uses a 31bit address space on top of 2^14 byte blocks.
+ *
+ * Therefore there is 2^31*2^14 = 2^45 or 32 terabytes max of addressable space.
+ *
+ * Some amount of the space is taken up by system information (inodes and use flags).
+ * This is held in a separate file.
+ *
+ * The 64 byte inode format is:
+ * 14 32 bit direct block pointers
+ * 1 32 bit block indirect pointer
+ * 1 32 bit block doubly indirect pointer
+ *
+ * The data block format is:
+ * data bytes | long gid | long oid | three byte int block num
+ *
+ * The gid/oid are stored with the block so that defrag/compaction can be performed
+ * with minimal blocking/lookups.
+ *
+ * This means that the maximum number of blocks available to a "file" is
+ * 14 + (2^14-18)/4 + ((2^14-18)/4)^2 ~= 2^24
+ *
+ * Thus the max serialized object size is: 2^24*(2^14-18) ~= 256GB.
+ *
+ * The root directory "physicalMapping" is held in memory for performance,
+ * but could itself be switched to using a block map. It will grow in
+ * proportion to the number of tables/tuplebuffers in use.
+ *
+ * TODO: defragment
+ * TODO: lobs could also be supported in this structure.
+ */
+public class FileStoreCache implements Cache, StorageManager {
+
+ //TODO allow the block size to be configurable
+ static final int LOG_BLOCK_SIZE = 14;
+ static final int ADDRESS_BITS = 31;
+ static final int SYSTEM_MASK = 1<<ADDRESS_BITS;
+ static final int BLOCK_SIZE = 1 << LOG_BLOCK_SIZE;
+ static final int BLOCK_MASK = BLOCK_SIZE - 1;
+ static final int BLOCK_OVERHEAD = 8+8+3;
+ static final int BLOCK_DATA_BYTES = BLOCK_SIZE - BLOCK_OVERHEAD;
+ static final int BYTES_PER_BLOCK_ADDRESS = 4;
+ static final int ADDRESSES_PER_BLOCK = BLOCK_DATA_BYTES/BYTES_PER_BLOCK_ADDRESS;
+ static final int INODE_BYTES = 16*BYTES_PER_BLOCK_ADDRESS;
+ static final int DIRECT_POINTERS = 14;
+ static final int MAX_INDIRECT = DIRECT_POINTERS + ADDRESSES_PER_BLOCK;
+ static final int MAX_DOUBLE_INDIRECT = MAX_INDIRECT + ADDRESSES_PER_BLOCK * ADDRESSES_PER_BLOCK;
+ static final int EMPTY_ADDRESS = -1;
+
+ private final class BlockOutputStream extends
+ ExtensibleBufferedOutputStream {
+ private final BlockManager blockManager;
+ int blockNum = -1;
+ BlockInfo bi;
+
+ private BlockOutputStream(BlockManager blockManager) {
+ this.blockManager = blockManager;
+ }
+
+ @Override
+ protected ByteBuffer newBuffer() {
+ bi = blockManager.allocateBlock(++blockNum);
+ return bi.buf;
+ }
+
+ @Override
+ protected void flushDirect() throws IOException {
+ blockManager.updateBlock(bi);
+ bi = null;
+ }
+ }
+
+ private final class BitSetBlockManager implements BlockManager {
+ final int offset;
+
+ BitSetBlockManager(int offset) {
+ this.offset = offset;
+ }
+
+ @Override
+ public void updateBlock(BlockInfo info) {
+ updatePhysicalBlock(info);
+ }
+
+ @Override
+ public BlockInfo getBlock(int index) {
+ return getPhysicalBlock(index + offset, true, false);
+ }
+
+ @Override
+ public BlockInfo allocateBlock(int index) {
+ return getPhysicalBlock(index + offset, true, true);
+ }
+
+ @Override
+ public int getInode() {
+ throw new AssertionError();
+ }
+
+ @Override
+ public void freeBlock(int index) {
+ throw new AssertionError();
+ }
+
+ @Override
+ public void free() {
+ throw new AssertionError();
+ }
+
+ }
+
+ private enum Mode {
+ GET,
+ UPDATE,
+ ALLOCATE
+ }
+
+ static final class BlockInfo {
+ final boolean system;
+ final int inodeOffset;
+ final ByteBuffer buf;
+ final int physicalAddress;
+ boolean dirty;
+
+ BlockInfo(boolean system, ByteBuffer ib, int index, int inodeOffset) {
+ this.system = system;
+ this.buf = ib;
+ this.physicalAddress = index;
+ this.inodeOffset = inodeOffset;
+ }
+ }
+
+ private final class InodeBlockManager implements BlockManager {
+ private final int inode;
+ private final long gid;
+ private final long oid;
+ private int lastBlock = -1;
+ boolean trackLast;
+
+ InodeBlockManager(long gid, long oid, int inode) {
+ if (inode == EMPTY_ADDRESS) {
+ synchronized (inodesInuse) {
+ inode = inodesInuse.nextClearBit(0);
+ if (inode == -1) {
+ throw new TeiidRuntimeException("no inodes available"); //$NON-NLS-1$
+ }
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.TRACE)) {
+ LogManager.logTrace(LogConstants.CTX_DQP, "Allocating inode", inode, "to", gid, oid); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ inodesInuse.set(inode, true);
+ }
+ int inodeBlock = inode/inodesPerBlock;
+ int inodePosition = INODE_BYTES*(inode%inodesPerBlock);
+ BlockInfo bb = getInodeSubBlock(inodeBlock, inodePosition);
+ bb.buf.putInt(EMPTY_ADDRESS);
+ updatePhysicalBlock(bb);
+ }
+ this.inode = inode;
+ this.gid = gid;
+ this.oid = oid;
+ }
+
+ @Override
+ public int getInode() {
+ return inode;
+ }
+
+ @Override
+ public void updateBlock(BlockInfo info) {
+ updatePhysicalBlock(info);
+ }
+
+ @Override
+ public BlockInfo getBlock(int index) {
+ int dataBlock = getOrUpdateDataBlockIndex(index, EMPTY_ADDRESS, Mode.GET);
+ BlockInfo bb = getPhysicalBlock(dataBlock, false, false);
+ bb.buf.position(0);
+ bb.buf.limit(BLOCK_DATA_BYTES);
+ return bb;
+ }
+
+ private int getOrUpdateDataBlockIndex(int index, int value, Mode mode) {
+ if (index >= MAX_DOUBLE_INDIRECT) {
+ throw new TeiidRuntimeException("Max block number exceeded"); //$NON-NLS-1$
+ }
+ int dataBlock = 0;
+ int position = 0;
+ int inodePosition = INODE_BYTES*(inode%inodesPerBlock);
+ BlockInfo info = getInodeSubBlock(inode/inodesPerBlock, inodePosition);
+ if (index >= MAX_INDIRECT) {
+ position = BYTES_PER_BLOCK_ADDRESS*(DIRECT_POINTERS+1);
+ BlockInfo next = updateIndirectBlockInfo(info, index, position, MAX_INDIRECT, MAX_DOUBLE_INDIRECT+1, value, mode);
+ if (next != info) {
+ info = next;
+ //should have traversed to the secondary
+ int indirectAddressBlock = (index - MAX_INDIRECT) / ADDRESSES_PER_BLOCK;
+ position = indirectAddressBlock * BYTES_PER_BLOCK_ADDRESS;
+ if (mode == Mode.ALLOCATE && position + BYTES_PER_BLOCK_ADDRESS < BLOCK_DATA_BYTES) {
+ info.buf.putInt(position + BYTES_PER_BLOCK_ADDRESS, EMPTY_ADDRESS);
+ }
+ next = updateIndirectBlockInfo(info, index, position, MAX_INDIRECT + indirectAddressBlock * ADDRESSES_PER_BLOCK, MAX_DOUBLE_INDIRECT + 2 + indirectAddressBlock, value, mode);
+ if (next != info) {
+ info = next;
+ position = ((index - MAX_INDIRECT)%ADDRESSES_PER_BLOCK) * BYTES_PER_BLOCK_ADDRESS;
+ if (mode == Mode.ALLOCATE && position + BYTES_PER_BLOCK_ADDRESS < BLOCK_DATA_BYTES) {
+ info.buf.putInt(position + BYTES_PER_BLOCK_ADDRESS, EMPTY_ADDRESS);
+ }
+ }
+ }
+ } else if (index >= DIRECT_POINTERS) {
+ //indirect
+ position = BYTES_PER_BLOCK_ADDRESS*DIRECT_POINTERS;
+ BlockInfo next = updateIndirectBlockInfo(info, index, position, DIRECT_POINTERS, MAX_DOUBLE_INDIRECT, value, mode);
+ if (next != info) {
+ info = next;
+ position = (index - DIRECT_POINTERS) * BYTES_PER_BLOCK_ADDRESS;
+ if (mode == Mode.ALLOCATE && position + BYTES_PER_BLOCK_ADDRESS < BLOCK_DATA_BYTES) {
+ info.buf.putInt(position + BYTES_PER_BLOCK_ADDRESS, EMPTY_ADDRESS);
+ }
+ }
+ } else {
+ position = BYTES_PER_BLOCK_ADDRESS*index;
+ if (mode == Mode.ALLOCATE) {
+ info.buf.putInt(position + BYTES_PER_BLOCK_ADDRESS, EMPTY_ADDRESS);
+ }
+ }
+ if (mode == Mode.ALLOCATE) {
+ dataBlock = nextBlock();
+ info.buf.putInt(position, dataBlock);
+ updatePhysicalBlock(info);
+ } else {
+ dataBlock = info.buf.getInt(position);
+ if (mode == Mode.UPDATE) {
+ info.buf.putInt(position, value);
+ updatePhysicalBlock(info);
+ }
+ }
+ return dataBlock;
+ }
+
+ private BlockInfo updateIndirectBlockInfo(BlockInfo info, int index, int position, int cutOff, int blockId, int value, Mode mode) {
+ int sib_index = info.buf.getInt(position);
+ boolean newBlock = false;
+ if (index == cutOff) {
+ if (mode == Mode.ALLOCATE) {
+ sib_index = nextBlock();
+ info.buf.putInt(position, sib_index);
+ updatePhysicalBlock(info);
+ newBlock = true;
+ } else if (mode == Mode.UPDATE && value == EMPTY_ADDRESS) {
+ freeDataBlock(sib_index);
+ return info;
+ }
+ }
+ info = getPhysicalBlock(sib_index, false, false);
+ if (newBlock) {
+ putBlockId(blockId, info.buf);
+ }
+ return info;
+ }
+
+ private int nextBlock() {
+ int next = -1;
+ synchronized (blocksInuse) {
+ next = blocksInuse.nextClearBit(lastBlock + 1);
+ if (next == -1) {
+ throw new TeiidRuntimeException("no freespace available"); //$NON-NLS-1$
+ }
+ blocksInuse.set(next, true);
+ }
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.TRACE)) {
+ LogManager.logTrace(LogConstants.CTX_DQP, "Allocating block", next, "to", gid, oid); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ if (trackLast) {
+ lastBlock = next;
+ }
+ return next;
+ }
+
+ @Override
+ public void freeBlock(int index) {
+ int dataBlock = getOrUpdateDataBlockIndex(index, EMPTY_ADDRESS, Mode.UPDATE);
+ freeDataBlock(dataBlock);
+ }
+
+ private void freeDataBlock(int dataBlock) {
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.TRACE)) {
+ LogManager.logTrace(LogConstants.CTX_DQP, "freeing data block", dataBlock, "for", gid, oid); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ blockCache.remove(dataBlock);
+ blocksInuse.set(dataBlock, false);
+ }
+
+ BlockInfo getInodeSubBlock(int inodeBlock, int inodePosition) {
+ BlockInfo bi = getPhysicalBlock(inodeBlock + blocksInUseBlocks + inodesInUseBlocks, true, false);
+ ByteBuffer bb = bi.buf.duplicate();
+ bb.position(inodePosition);
+ bb.limit(inodePosition + INODE_BYTES);
+ bb = bb.slice();
+ return new BlockInfo(true, bb, inodeBlock + blocksInUseBlocks + inodesInUseBlocks, inodePosition);
+ }
+
+ @Override
+ public void free() {
+ int inodeBlock = inode/inodesPerBlock;
+ int inodePosition = INODE_BYTES*(inode%inodesPerBlock);
+ BlockInfo bi = getInodeSubBlock(inodeBlock, inodePosition);
+ ByteBuffer ib = bi.buf;
+ int indirectIndexBlock = ib.getInt(ib.position() + BYTES_PER_BLOCK_ADDRESS*DIRECT_POINTERS);
+ int doublyIndirectIndexBlock = ib.getInt(ib.position() + BYTES_PER_BLOCK_ADDRESS*(DIRECT_POINTERS+1));
+ boolean freedAll = freeBlock(ib, DIRECT_POINTERS, true);
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.TRACE)) {
+ LogManager.logTrace(LogConstants.CTX_DQP, "freeing inode", inode, "for", gid, oid); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ inodesInuse.set(inode, false);
+ if (!freedAll || indirectIndexBlock == EMPTY_ADDRESS) {
+ return;
+ }
+ freedAll = freeIndirectBlock(indirectIndexBlock);
+ if (!freedAll || doublyIndirectIndexBlock == EMPTY_ADDRESS) {
+ return;
+ }
+ BlockInfo bb = getPhysicalBlock(doublyIndirectIndexBlock, false, false);
+ freeBlock(bb.buf, ADDRESSES_PER_BLOCK, false);
+ freeDataBlock(doublyIndirectIndexBlock);
+ }
+
+ private boolean freeIndirectBlock(int indirectIndexBlock) {
+ BlockInfo bb = getPhysicalBlock(indirectIndexBlock, false, false);
+ bb.buf.position(0);
+ boolean freedAll = freeBlock(bb.buf, ADDRESSES_PER_BLOCK, true);
+ freeDataBlock(indirectIndexBlock);
+ return freedAll;
+ }
+
+ private boolean freeBlock(ByteBuffer ib, int numPointers, boolean primary) {
+ for (int i = 0; i < numPointers; i++) {
+ int dataBlock = ib.getInt();
+ if (dataBlock == EMPTY_ADDRESS) {
+ return false;
+ }
+ if (primary) {
+ freeDataBlock(dataBlock);
+ } else {
+ freeIndirectBlock(dataBlock);
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public BlockInfo allocateBlock(int blockNum) {
+ int dataBlock = getOrUpdateDataBlockIndex(blockNum, EMPTY_ADDRESS, Mode.ALLOCATE);
+ BlockInfo bb = getPhysicalBlock(dataBlock, false, true);
+ putBlockId(blockNum, bb.buf);
+ bb.buf.position(0);
+ bb.buf.limit(BLOCK_DATA_BYTES);
+ return bb;
+ }
+
+ private void putBlockId(int blockNum, ByteBuffer bb) {
+ bb.position(BLOCK_DATA_BYTES);
+ bb.putLong(gid);
+ bb.putLong(oid);
+ bb.put((byte)(blockNum >> 16));
+ bb.putShort((short)blockNum);
+ }
+
+ }
+
+ private StorageManager storageManager;
+ private long maxBufferSpace = FileStorageManager.DEFAULT_MAX_BUFFERSPACE;
+ private int inodes;
+ private int blocks;
+ private int inodesPerBlock;
+ private int inodesInUseBlocks;
+ private int blocksInUseBlocks;
+ private FileStore store;
+ private FileStore systemStore;
+ private BlockBitSetTree blocksInuse;
+ private BlockBitSetTree inodesInuse;
+
+ //root directory
+ ConcurrentHashMap<Long, BlockClosedLongIntHashTable> physicalMapping = new ConcurrentHashMap<Long, BlockClosedLongIntHashTable>();
+
+ //block caching
+ int blockCacheSize = 128; //2 MB
+ ReentrantLock blockLock = new ReentrantLock();
+ LinkedHashMap<Integer, BlockInfo> blockCache = new LinkedHashMap<Integer, BlockInfo>() {
+ private static final long serialVersionUID = -4240291744435552008L;
+ BlockInfo eldestEntry = null;
+
+ protected boolean removeEldestEntry(Map.Entry<Integer,BlockInfo> eldest) {
+ if (size() > blockCacheSize) {
+ BlockInfo bi = eldest.getValue();
+ if (bi.dirty) {
+ eldestEntry = bi;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public BlockInfo put(Integer key, BlockInfo value) {
+ blockLock.lock();
+ value.dirty = true;
+ try {
+ return super.put(key, value);
+ } finally {
+ BlockInfo toUpdate = eldestEntry;
+ eldestEntry = null;
+ blockLock.unlock();
+ if (toUpdate != null) {
+ updatePhysicalBlockDirect(toUpdate);
+ }
+ }
+ }
+
+ public BlockInfo get(Object key) {
+ blockLock.lock();
+ try {
+ return super.get(key);
+ } finally {
+ blockLock.unlock();
+ }
+ }
+
+ public BlockInfo remove(Object key) {
+ blockLock.lock();
+ try {
+ return super.remove(key);
+ } finally {
+ blockLock.unlock();
+ }
+ }
+ };
+
+ BlockInfo getPhysicalBlock(int block, boolean system, boolean allocate) {
+ if (block < 0) {
+ throw new AssertionError("invalid block address " + block); //$NON-NLS-1$
+ }
+ try {
+ int key = block;
+ if (system) {
+ key |= SYSTEM_MASK;
+ }
+ BlockInfo result = blockCache.get(key);
+ assert result == null || !allocate;
+ if (result == null) {
+ ByteBuffer bb = null;
+ if (system) {
+ bb = systemStore.getBuffer(block<<LOG_BLOCK_SIZE, BLOCK_SIZE, allocate);
+ } else {
+ bb = store.getBuffer(block<<LOG_BLOCK_SIZE, BLOCK_SIZE, allocate);
+ }
+ result = new BlockInfo(system, bb, block, -1);
+ blockLock.lock();
+ try {
+ BlockInfo existing = blockCache.get(key);
+ if (existing != null) {
+ return existing;
+ }
+ blockCache.put(key, result);
+ } finally {
+ blockLock.unlock();
+ }
+ return result;
+ }
+ return result;
+ } catch (IOException e) {
+ throw new TeiidRuntimeException(e);
+ }
+ }
+
+ void updatePhysicalBlock(BlockInfo bi) {
+ int key = bi.physicalAddress;
+ if (bi.system) {
+ key |= SYSTEM_MASK;
+ }
+ if (bi.inodeOffset >= 0) {
+ blockLock.lock();
+ try {
+ BlockInfo actual = blockCache.get(key);
+ if (actual == null) {
+ //we're not in the cache, so just update storage
+ updatePhysicalBlockDirect(bi);
+ } else {
+ //TODO: check to see we're sharing the same buffer
+ for (int i = 0; i < INODE_BYTES; i++) {
+ actual.buf.put(bi.inodeOffset + i, bi.buf.get(i));
+ }
+ }
+ } finally {
+ blockLock.unlock();
+ }
+ return;
+ }
+ blockCache.put(key, bi);
+ }
+
+ private void updatePhysicalBlockDirect(BlockInfo bi) {
+ try {
+ bi.buf.rewind();
+ if (!bi.system) {
+ store.updateFromBuffer(bi.buf, bi.physicalAddress<<LOG_BLOCK_SIZE);
+ } else {
+ systemStore.updateFromBuffer(bi.buf, bi.physicalAddress<<LOG_BLOCK_SIZE);
+ }
+ } catch (IOException e) {
+ throw new TeiidRuntimeException(e);
+ }
+ }
+
+ InodeBlockManager getBlockManager(long gid, long oid, int inode) {
+ return new InodeBlockManager(gid, oid, inode);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void add(CacheEntry entry, Serializer s) {
+ boolean success = false;
+ InodeBlockManager blockManager = null;
+ try {
+ BlockClosedLongIntHashTable map = physicalMapping.get(s.getId());
+ if (map == null) {
+ return;
+ }
+ blockManager = getBlockManager(s.getId(), entry.getId(), EMPTY_ADDRESS);
+ blockManager.trackLast = true;
+ ExtensibleBufferedOutputStream fsos = new BlockOutputStream(blockManager);
+ ObjectOutputStream oos = new ObjectOutputStream(fsos);
+ oos.writeInt(entry.getSizeEstimate());
+ s.serialize(entry.getObject(), oos);
+ oos.close();
+ map.put(entry.getId(), blockManager.getInode());
+ success = true;
+ } catch (Throwable e) {
+ LogManager.logError(LogConstants.CTX_BUFFER_MGR, e, "Error persisting batch, attempts to read batch "+ entry.getId() +" later will result in an exception"); //$NON-NLS-1$ //$NON-NLS-2$
+ } finally {
+ if (!success && blockManager != null) {
+ blockManager.free();
+ }
+ }
+ }
+
+ @Override
+ public CacheEntry get(Long oid, Serializer<?> serializer) throws TeiidComponentException {
+ try {
+ BlockClosedLongIntHashTable map = physicalMapping.get(serializer.getId());
+ if (map == null) {
+ return null;
+ }
+ final int inode = map.get(oid);
+ if (inode == EMPTY_ADDRESS) {
+ return null;
+ }
+ final BlockManager manager = getBlockManager(serializer.getId(), oid, inode);
+ ObjectInputStream ois = new ObjectInputStream(new InputStream() {
+
+ int blockIndex;
+ BlockInfo buf;
+
+ @Override
+ public int read() throws IOException {
+ ensureBytes();
+ return buf.buf.get() & 0xff;
+ }
+
+ private void ensureBytes() {
+ if (buf == null || buf.buf.remaining() == 0) {
+ if (buf != null) {
+ buf = null;
+ }
+ buf = manager.getBlock(blockIndex++);
+ }
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len)
+ throws IOException {
+ ensureBytes();
+ len = Math.min(len, buf.buf.remaining());
+ buf.buf.get(b, off, len);
+ return len;
+ }
+ });
+ CacheEntry ce = new CacheEntry(oid);
+ ce.setSizeEstimate(ois.readInt());
+ ce.setObject(serializer.deserialize(ois));
+ ce.setPersistent(true);
+ return ce;
+ } catch(IOException e) {
+ throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", oid)); //$NON-NLS-1$
+ } catch (ClassNotFoundException e) {
+ throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", oid)); //$NON-NLS-1$
+ }
+ }
+
+ @Override
+ public FileStore createFileStore(String name) {
+ return storageManager.createFileStore(name);
+ }
+
+ @Override
+ public void initialize() throws TeiidComponentException {
+ storageManager.initialize();
+ int logSpace = Math.min(45, 63 - Long.numberOfLeadingZeros(this.maxBufferSpace));
+
+ blocks = 1 << Math.min(Math.max(12, logSpace -LOG_BLOCK_SIZE +1), ADDRESS_BITS); //blocks per segment
+
+ inodes = blocks>>1;
+ inodesPerBlock = BLOCK_SIZE/INODE_BYTES;
+
+ inodesInUseBlocks = computeInuseBlocks(inodes);
+ blocksInUseBlocks = computeInuseBlocks(blocks);
+
+ inodesInuse = new BlockBitSetTree(inodes - 1, new BitSetBlockManager(0));
+ blocksInuse = new BlockBitSetTree(blocks - 1, new BitSetBlockManager(inodesInUseBlocks));
+
+ store = storageManager.createFileStore("data_store"); //$NON-NLS-1$
+ systemStore = storageManager.createFileStore("system_store"); //$NON-NLS-1$
+ }
+
+ static int computeInuseBlocks(int number) {
+ int blockCount = (number>>LOG_BLOCK_SIZE) + ((number&BLOCK_MASK)>0?1:0);
+ return (blockCount>>3) + ((blockCount&7)>0?1:0);
+ }
+
+ @Override
+ public void addToCacheGroup(Long gid, Long oid) {
+ BlockClosedLongIntHashTable map = physicalMapping.get(gid);
+ if (map == null) {
+ return;
+ }
+ map.put(oid, EMPTY_ADDRESS);
+ }
+
+ @Override
+ public void createCacheGroup(Long gid) {
+ BlockClosedLongIntHashTable map = new BlockClosedLongIntHashTable(getBlockManager(gid, -1, EMPTY_ADDRESS));
+ physicalMapping.put(gid, map);
+ }
+
+ @Override
+ public void remove(Long gid, Long id) {
+ BlockClosedLongIntHashTable map = physicalMapping.get(gid);
+ if (map == null) {
+ return;
+ }
+ int inode = map.remove(id);
+ free(gid, id, inode);
+ }
+
+ @Override
+ public Collection<Long> removeCacheGroup(Long gid) {
+ BlockClosedLongIntHashTable map = physicalMapping.remove(gid);
+ if (map == null) {
+ return Collections.emptySet();
+ }
+ Map<Long, Integer> values = map.remove();
+ for (Map.Entry<Long, Integer> entry : values.entrySet()) {
+ if (entry.getValue() != null) {
+ free(gid, entry.getKey(), entry.getValue());
+ }
+ }
+ return values.keySet();
+ }
+
+ void free(Long gid, Long oid, int inode) {
+ if (inode == EMPTY_ADDRESS) {
+ return;
+ }
+ BlockManager bm = getBlockManager(gid, oid, inode);
+ bm.free();
+ }
+
+ public void setStorageManager(StorageManager storageManager) {
+ this.storageManager = storageManager;
+ }
+
+ public StorageManager getStorageManager() {
+ return storageManager;
+ }
+
+ public void setMaxBufferSpace(long maxBufferSpace) {
+ this.maxBufferSpace = maxBufferSpace;
+ }
+
+ public int getInodesInUse() {
+ return this.inodesInuse.getBitsSet();
+ }
+
+ public int getDataBlocksInUse() {
+ return this.blocksInuse.getBitsSet();
+ }
+
+}
Modified: branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/MemoryStorageManager.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/MemoryStorageManager.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/MemoryStorageManager.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -22,16 +22,89 @@
package org.teiid.common.buffer.impl;
+import java.io.IOException;
import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
+import org.teiid.common.buffer.Cache;
+import org.teiid.common.buffer.CacheEntry;
import org.teiid.common.buffer.FileStore;
-import org.teiid.common.buffer.StorageManager;
+import org.teiid.common.buffer.Serializer;
import org.teiid.core.TeiidComponentException;
-public class MemoryStorageManager implements StorageManager {
+public class MemoryStorageManager implements Cache {
+
+ public static final int MAX_FILE_SIZE = 1 << 17;
+ private final class MemoryFileStore extends FileStore {
+ private ByteBuffer buffer = ByteBuffer.allocate(MAX_FILE_SIZE);
+
+ public MemoryFileStore() {
+ buffer.limit(0);
+ }
+
+ @Override
+ public synchronized void removeDirect() {
+ removed.incrementAndGet();
+ buffer = ByteBuffer.allocate(0);
+ }
+
+ @Override
+ protected synchronized int readWrite(long fileOffset, byte[] b, int offSet,
+ int length, boolean write) {
+ if (!write) {
+ if (fileOffset >= getLength()) {
+ return -1;
+ }
+ int position = (int)fileOffset;
+ buffer.position(position);
+ length = Math.min(length, (int)getLength() - position);
+ buffer.get(b, offSet, length);
+ return length;
+ }
+ int requiredLength = (int)(fileOffset + length);
+ if (requiredLength > buffer.limit()) {
+ buffer.limit(requiredLength);
+ }
+ buffer.position((int)fileOffset);
+ buffer.put(b, offSet, length);
+ return length;
+ }
+
+ @Override
+ public synchronized void setLength(long length) {
+ buffer.limit((int)length);
+ }
+
+ @Override
+ public synchronized long getLength() {
+ return buffer.limit();
+ }
+
+ @Override
+ public synchronized ByteBuffer getBuffer(long start, int length, boolean allocate) {
+ int position = (int)start;
+ buffer.limit(position + length);
+ buffer.position(position);
+ return buffer.slice();
+ }
+
+ @Override
+ public void updateFromBuffer(ByteBuffer bb, long start)
+ throws IOException {
+ //do nothing we are sharing the bytes
+ }
+
+ }
+
+ private Map<Long, Map<Long, CacheEntry>> groups = new ConcurrentHashMap<Long, Map<Long, CacheEntry>>();
private AtomicInteger created = new AtomicInteger();
private AtomicInteger removed = new AtomicInteger();
@@ -41,40 +114,7 @@
@Override
public FileStore createFileStore(String name) {
created.incrementAndGet();
- return new FileStore() {
- private ByteBuffer buffer = ByteBuffer.allocate(1 << 16);
-
- @Override
- public void writeDirect(byte[] bytes, int offset, int length) throws TeiidComponentException {
- if (getLength() + length > buffer.capacity()) {
- ByteBuffer newBuffer = ByteBuffer.allocate(buffer.capacity() * 2 + length);
- buffer.position(0);
- newBuffer.put(buffer);
- buffer = newBuffer;
- }
- buffer.position((int)getLength());
- buffer.put(bytes, offset, length);
- }
-
- @Override
- public synchronized void removeDirect() {
- removed.incrementAndGet();
- buffer = ByteBuffer.allocate(0);
- }
-
- @Override
- public synchronized int readDirect(long fileOffset, byte[] b, int offset, int length)
- throws TeiidComponentException {
- if (fileOffset >= getLength()) {
- return -1;
- }
- int position = (int)fileOffset;
- buffer.position(position);
- length = Math.min(length, (int)getLength() - position);
- buffer.get(b, offset, length);
- return length;
- }
- };
+ return new MemoryFileStore();
}
public int getCreated() {
@@ -84,4 +124,55 @@
public int getRemoved() {
return removed.get();
}
+
+ @Override
+ public void add(CacheEntry entry, Serializer<?> s) {
+ Map<Long, CacheEntry> group = groups.get(s.getId());
+ if (group != null) {
+ group.put(entry.getId(), entry);
+ }
+ }
+
+ @Override
+ public void addToCacheGroup(Long gid, Long oid) {
+ Map<Long, CacheEntry> group = groups.get(gid);
+ if (group != null) {
+ group.put(oid, null);
+ }
+ }
+
+ @Override
+ public void createCacheGroup(Long gid) {
+ groups.put(gid, Collections.synchronizedMap(new HashMap<Long, CacheEntry>()));
+ }
+
+ @Override
+ public CacheEntry get(Long id, Serializer<?> serializer)
+ throws TeiidComponentException {
+ Map<Long, CacheEntry> group = groups.get(serializer.getId());
+ if (group != null) {
+ return group.get(id);
+ }
+ return null;
+ }
+
+ @Override
+ public void remove(Long gid, Long id) {
+ Map<Long, CacheEntry> group = groups.get(gid);
+ if (group != null) {
+ group.remove(id);
+ }
+ }
+
+ @Override
+ public Collection<Long> removeCacheGroup(Long gid) {
+ Map<Long, CacheEntry> group = groups.remove(gid);
+ if (group == null) {
+ return Collections.emptySet();
+ }
+ synchronized (group) {
+ return new ArrayList<Long>(group.keySet());
+ }
+ }
+
}
\ No newline at end of file
Modified: branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/SizeUtility.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/SizeUtility.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/SizeUtility.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -25,8 +25,10 @@
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
-import org.teiid.common.buffer.TupleBatch;
import org.teiid.core.types.DataTypeManager;
@@ -40,29 +42,52 @@
public final class SizeUtility {
public static final int REFERENCE_SIZE = 8;
+ private static Map<Class<?>, int[]> SIZE_ESTIMATES = new HashMap<Class<?>, int[]>(128);
+
+ static {
+ SIZE_ESTIMATES.put(DataTypeManager.DefaultDataClasses.STRING, new int[] {100, 256});
+ SIZE_ESTIMATES.put(DataTypeManager.DefaultDataClasses.DATE, new int[] {20, 28});
+ SIZE_ESTIMATES.put(DataTypeManager.DefaultDataClasses.TIME, new int[] {20, 28});
+ SIZE_ESTIMATES.put(DataTypeManager.DefaultDataClasses.TIMESTAMP, new int[] {20, 28});
+ SIZE_ESTIMATES.put(DataTypeManager.DefaultDataClasses.LONG, new int[] {12, 16});
+ SIZE_ESTIMATES.put(DataTypeManager.DefaultDataClasses.DOUBLE, new int[] {12, 16});
+ SIZE_ESTIMATES.put(DataTypeManager.DefaultDataClasses.INTEGER, new int[] {6, 12});
+ SIZE_ESTIMATES.put(DataTypeManager.DefaultDataClasses.FLOAT, new int[] {6, 12});
+ SIZE_ESTIMATES.put(DataTypeManager.DefaultDataClasses.CHAR, new int[] {4, 10});
+ SIZE_ESTIMATES.put(DataTypeManager.DefaultDataClasses.SHORT, new int[] {4, 10});
+ SIZE_ESTIMATES.put(DataTypeManager.DefaultDataClasses.OBJECT, new int[] {1024, 1024});
+ SIZE_ESTIMATES.put(DataTypeManager.DefaultDataClasses.NULL, new int[] {0, 0});
+ SIZE_ESTIMATES.put(DataTypeManager.DefaultDataClasses.BYTE, new int[] {1, 1});
+ SIZE_ESTIMATES.put(DataTypeManager.DefaultDataClasses.BOOLEAN, new int[] {1, 1});
+ SIZE_ESTIMATES.put(DataTypeManager.DefaultDataClasses.BIG_INTEGER, new int[] {75, 100});
+ SIZE_ESTIMATES.put(DataTypeManager.DefaultDataClasses.BIG_DECIMAL, new int[] {150, 200});
+ }
+
private long bigIntegerEstimate;
private long bigDecimalEstimate;
+ private String[] types;
- public SizeUtility() {
+ public SizeUtility(String[] types) {
boolean isValueCacheEnabled = DataTypeManager.isValueCacheEnabled();
bigIntegerEstimate = getSize(isValueCacheEnabled, DataTypeManager.DefaultDataClasses.BIG_INTEGER);
bigDecimalEstimate = getSize(isValueCacheEnabled, DataTypeManager.DefaultDataClasses.BIG_DECIMAL);
+ this.types = types;
}
- public long getBatchSize(TupleBatch data) {
+ public long getBatchSize(List<? extends List<?>> data) {
return getBatchSize(DataTypeManager.isValueCacheEnabled(), data);
}
- private long getBatchSize(boolean accountForValueCache, TupleBatch data) {
- int colLength = data.getDataTypes().length;
- int rowLength = data.getRowCount();
+ private long getBatchSize(boolean accountForValueCache, List<? extends List<?>> data) {
+ int colLength = types.length;
+ int rowLength = data.size();
// Array overhead for row array
long size = 16 + alignMemory(rowLength * REFERENCE_SIZE);
// array overhead for all the columns ( 8 object overhead + 4 ref + 4 int)
size += (rowLength * (48 + alignMemory(colLength * REFERENCE_SIZE)));
for (int col = 0; col < colLength; col++) {
- Class<?> type = DataTypeManager.getDataTypeClass(data.getDataTypes()[col]);
+ Class<?> type = DataTypeManager.getDataTypeClass(types[col]);
if (type == DataTypeManager.DefaultDataClasses.STRING
|| type == DataTypeManager.DefaultDataClasses.OBJECT
@@ -71,7 +96,7 @@
int estRow = 0;
for (int row = 0; row < rowLength; row++) {
boolean updateEst = row == estRow;
- size += getSize(data.getTuples().get(row).get(col), updateEst, accountForValueCache);
+ size += getSize(data.get(row).get(col), updateEst, accountForValueCache);
if (updateEst) {
estRow = estRow * 2 + 1;
}
@@ -85,36 +110,12 @@
static int getSize(boolean isValueCacheEnabled,
Class<?> type) {
- if (type == DataTypeManager.DefaultDataClasses.STRING) {
- return isValueCacheEnabled?100:256; //assumes an "average" string length of approximately 100 chars
- } else if (type == DataTypeManager.DefaultDataClasses.DATE
- || type == DataTypeManager.DefaultDataClasses.TIME
- || type == DataTypeManager.DefaultDataClasses.TIMESTAMP) {
- return isValueCacheEnabled?20:28;
- } else if (type == DataTypeManager.DefaultDataClasses.LONG
- || type == DataTypeManager.DefaultDataClasses.DOUBLE) {
- return isValueCacheEnabled?12:16;
- } else if (type == DataTypeManager.DefaultDataClasses.INTEGER
- || type == DataTypeManager.DefaultDataClasses.FLOAT) {
- return isValueCacheEnabled?6:12;
- } else if (type == DataTypeManager.DefaultDataClasses.CHAR
- || type == DataTypeManager.DefaultDataClasses.SHORT) {
- return isValueCacheEnabled?4:10;
- } else if (type == DataTypeManager.DefaultDataClasses.OBJECT) {
- return 1024;
- } else if (type == DataTypeManager.DefaultDataClasses.NULL) {
- return 0; //it's free
- } else if (type == DataTypeManager.DefaultDataClasses.BYTE
- || type == DataTypeManager.DefaultDataClasses.BOOLEAN) {
- return 1; //should always be value cached, but there's a small chance it's not
- } else if (type == DataTypeManager.DefaultDataClasses.BIG_INTEGER){
- return isValueCacheEnabled?75:100;
- } else if (type == DataTypeManager.DefaultDataClasses.BIG_DECIMAL) {
- return isValueCacheEnabled?150:200;
- }
- return 512; //assumes buffer overhead in the case of lobs
- //however the account for lobs is misleading as the lob
- //references are not actually removed from memory
+ int[] vals = SIZE_ESTIMATES.get(type);
+ if (vals == null) {
+ return 512; //this is is misleading for lobs
+ //most references are not actually removed from memory
+ }
+ return vals[isValueCacheEnabled?0:1];
}
/**
Copied: branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java (from rev 3506, trunk/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java)
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java (rev 0)
+++ branches/as7/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -0,0 +1,190 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer.impl;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.teiid.common.buffer.FileStore;
+import org.teiid.common.buffer.StorageManager;
+import org.teiid.core.TeiidComponentException;
+
+/**
+ * A storage manager that combines smaller files into a larger
+ * logical file.
+ *
+ * The buffer methods assume that buffers cannot go beyond single
+ * file boundaries.
+ */
+public class SplittableStorageManager implements StorageManager {
+
+ public static final long DEFAULT_MAX_FILESIZE = 2 * 1024l;
+ private long maxFileSize = DEFAULT_MAX_FILESIZE * 1024l * 1024l; // 2GB
+ private StorageManager storageManager;
+
+ public SplittableStorageManager(StorageManager storageManager) {
+ this.storageManager = storageManager;
+ }
+
+ @Override
+ public FileStore createFileStore(String name) {
+ return new SplittableFileStore(name);
+ }
+
+ @Override
+ public void initialize() throws TeiidComponentException {
+ storageManager.initialize();
+ }
+
+ public class SplittableFileStore extends FileStore {
+ private String name;
+ private List<FileStore> storageFiles = new ArrayList<FileStore>();
+
+ private volatile long len;
+
+ public SplittableFileStore(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public long getLength() {
+ return len;
+ }
+
+ @Override
+ protected int readWrite(long fileOffset, byte[] b, int offSet,
+ int length, boolean write) throws IOException {
+ FileStore store = null;
+ if (!write) {
+ synchronized (this) {
+ if (fileOffset + length > len) {
+ throw new IOException("Invalid file position " + fileOffset + " length " + length); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ store = storageFiles.get((int)(fileOffset/maxFileSize));
+ }
+ return store.read(fileOffset%maxFileSize, b, offSet, length);
+ }
+ synchronized (this) {
+ ensureLength(fileOffset + length);
+ store = storageFiles.get((int)(fileOffset/maxFileSize));
+ }
+ long fileBegin = fileOffset%maxFileSize;
+ length = Math.min(length, (int)Math.min(Integer.MAX_VALUE, maxFileSize - fileBegin));
+ store.write(fileBegin, b, offSet, length);
+ return length;
+ }
+
+ private void ensureLength(long length) throws IOException {
+ if (length <= len) {
+ return;
+ }
+ int numFiles = (int)(length/maxFileSize);
+ long lastFileSize = length%maxFileSize;
+ if (lastFileSize > 0) {
+ numFiles++;
+ }
+ for (int i = storageFiles.size(); i < numFiles; i++) {
+ FileStore newFileInfo = storageManager.createFileStore(name + "_" + storageFiles.size()); //$NON-NLS-1$
+ storageFiles.add(newFileInfo);
+ if (lastFileSize == 0 || i != numFiles - 1) {
+ newFileInfo.setLength(maxFileSize);
+ }
+ }
+ if (lastFileSize > 0) {
+ storageFiles.get(storageFiles.size() - 1).setLength(lastFileSize);
+ }
+ len = length;
+ }
+
+ @Override
+ public ByteBuffer getBuffer(long start, int length, boolean allocate) throws IOException {
+ FileStore store = null;
+ synchronized (this) {
+ ensureLength(start + length);
+ store = storageFiles.get((int)(start/maxFileSize));
+ }
+ long fileBegin = start%maxFileSize;
+ return store.getBuffer(fileBegin, length, allocate);
+ }
+
+ @Override
+ public void updateFromBuffer(ByteBuffer bb, long start)
+ throws IOException {
+ FileStore store = null;
+ synchronized (this) {
+ store = storageFiles.get((int)(start/maxFileSize));
+ }
+ long fileBegin = start%maxFileSize;
+ store.updateFromBuffer(bb, fileBegin);
+ }
+
+ @Override
+ public synchronized void setLength(long length) throws IOException {
+ if (length > len) {
+ ensureLength(length);
+ } else {
+ int numFiles = (int)(length/maxFileSize);
+ long lastFileSize = length%maxFileSize;
+ if (lastFileSize > 0) {
+ numFiles++;
+ }
+ int toRemove = storageFiles.size() - numFiles;
+ for (int i = 0; i < toRemove; i++) {
+ FileStore store = storageFiles.remove(storageFiles.size() -1);
+ store.remove();
+ }
+ if (lastFileSize > 0) {
+ storageFiles.get(storageFiles.size() - 1).setLength(lastFileSize);
+ }
+ }
+ len = length;
+ }
+
+ public synchronized void removeDirect() {
+ for (FileStore info : storageFiles) {
+ info.remove();
+ }
+ storageFiles.clear();
+ }
+
+ }
+
+ public long getMaxFileSize() {
+ return maxFileSize;
+ }
+
+ public void setMaxFileSize(long maxFileSize) {
+ this.maxFileSize = maxFileSize * 1024l * 1024l;
+ }
+
+ public void setMaxFileSizeDirect(long maxFileSize) {
+ this.maxFileSize = maxFileSize;
+ }
+
+ public StorageManager getStorageManager() {
+ return storageManager;
+ }
+
+}
Modified: branches/as7/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -31,7 +31,6 @@
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.common.buffer.BlockedException;
-import org.teiid.common.buffer.TupleBuffer;
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.util.Assertion;
import org.teiid.dqp.message.AtomicRequestID;
@@ -332,7 +331,7 @@
LogManager.logWarning(LogConstants.CTX_CONNECTOR, QueryPlugin.Util.getString("ConnectorWorker.zero_size_non_last_batch", requestMsg.getConnectorName())); //$NON-NLS-1$
}
- AtomicResultsMessage response = createResultsMessage(rows.toArray(new List[currentRowCount]), requestMsg.getCommand().getProjectedSymbols());
+ AtomicResultsMessage response = createResultsMessage(rows.toArray(new List[currentRowCount]));
// if we need to keep the execution alive, then we can not support implicit close.
response.setSupportsImplicitClose(!this.securityContext.keepExecutionAlive());
@@ -346,9 +345,8 @@
return response;
}
- public static AtomicResultsMessage createResultsMessage(List[] batch, List columnSymbols) {
- String[] dataTypes = TupleBuffer.getTypeNames(columnSymbols);
- return new AtomicResultsMessage(batch, dataTypes);
+ public static AtomicResultsMessage createResultsMessage(List[] batch) {
+ return new AtomicResultsMessage(batch);
}
boolean isCancelled() {
Modified: branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -398,7 +398,7 @@
fullyCloseSource();
}
if(workItem.requestMsg.supportsPartialResults()) {
- AtomicResultsMessage emptyResults = new AtomicResultsMessage(new List[0], null);
+ AtomicResultsMessage emptyResults = new AtomicResultsMessage(new List[0]);
emptyResults.setWarnings(Arrays.asList((Exception)exception));
emptyResults.setFinalRow(this.rowsProcessed);
return emptyResults;
Modified: branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -233,7 +233,6 @@
props,
this.requestMsg.getShowPlan() != ShowPlan.OFF);
this.context.setProcessorBatchSize(bufferManager.getProcessorBatchSize());
- this.context.setConnectorBatchSize(bufferManager.getConnectorBatchSize());
this.context.setGlobalTableStore(this.globalTables);
if (multiSourceModels != null) {
MultiSourcePlanToProcessConverter modifier = new MultiSourcePlanToProcessConverter(
Modified: branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -25,12 +25,13 @@
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
-import java.util.concurrent.ConcurrentHashMap;
import org.teiid.client.RequestMessage;
import org.teiid.client.ResultsMessage;
@@ -144,7 +145,7 @@
* maintained during processing
*/
private Throwable processingException;
- private Map<AtomicRequestID, DataTierTupleSource> connectorInfo = new ConcurrentHashMap<AtomicRequestID, DataTierTupleSource>(4);
+ private Map<AtomicRequestID, DataTierTupleSource> connectorInfo = Collections.synchronizedMap(new HashMap<AtomicRequestID, DataTierTupleSource>(4));
// This exception contains details of all the atomic requests that failed when query is run in partial results mode.
private List<TeiidException> warnings = new LinkedList<TeiidException>();
private volatile boolean doneProducingBatches;
@@ -157,7 +158,7 @@
private int begin;
private int end;
private TupleBatch savedBatch;
- private Map<Integer, LobWorkItem> lobStreams = new ConcurrentHashMap<Integer, LobWorkItem>(4);
+ private Map<Integer, LobWorkItem> lobStreams = Collections.synchronizedMap(new HashMap<Integer, LobWorkItem>(4));
/**The time when command begins processing on the server.*/
private long processingTimestamp = System.currentTimeMillis();
@@ -362,7 +363,7 @@
* break the read of a lob from a transactional source under a transaction
* if the source does not support holding the clob open after commit
*/
- for (DataTierTupleSource connectorRequest : this.connectorInfo.values()) {
+ for (DataTierTupleSource connectorRequest : getConnectorRequests()) {
if (connectorRequest.isTransactional()) {
connectorRequest.fullyCloseSource();
}
@@ -401,15 +402,21 @@
}
}
- for (DataTierTupleSource connectorRequest : this.connectorInfo.values()) {
+ for (DataTierTupleSource connectorRequest : getConnectorRequests()) {
connectorRequest.fullyCloseSource();
}
}
this.resultsBuffer = null;
- for (LobWorkItem lobWorkItem : this.lobStreams.values()) {
- lobWorkItem.close();
+ if (!this.lobStreams.isEmpty()) {
+ List<LobWorkItem> lobs = null;
+ synchronized (lobStreams) {
+ lobs = new ArrayList<LobWorkItem>(this.lobStreams.values());
+ }
+ for (LobWorkItem lobWorkItem : lobs) {
+ lobWorkItem.close();
+ }
}
}
@@ -592,7 +599,7 @@
}
int finalRowCount = this.resultsBuffer.isFinal()?this.resultsBuffer.getRowCount():(batch.getTerminationFlag()?batch.getEndRow():-1);
- response = createResultsMessage(batch.getAllTuples(), this.originalCommand.getProjectedSymbols());
+ response = createResultsMessage(batch.getTuples(), this.originalCommand.getProjectedSymbols());
response.setFirstRow(batch.getBeginRow());
response.setLastRow(batch.getEndRow());
response.setUpdateResult(this.returnsUpdateCount);
@@ -631,7 +638,7 @@
return result;
}
- public ResultsMessage createResultsMessage(List[] batch, List columnSymbols) {
+ public ResultsMessage createResultsMessage(List<? extends List<?>> batch, List columnSymbols) {
String[] columnNames = new String[columnSymbols.size()];
String[] dataTypes = new String[columnSymbols.size()];
@@ -640,7 +647,7 @@
columnNames[i] = SingleElementSymbol.getShortName(symbol.getOutputName());
dataTypes[i] = DataTypeManager.getDataTypeName(symbol.getType());
}
- ResultsMessage result = new ResultsMessage(requestMsg, batch, columnNames, dataTypes);
+ ResultsMessage result = new ResultsMessage(batch, columnNames, dataTypes);
setAnalysisRecords(result);
return result;
}
@@ -672,7 +679,7 @@
}
}
LogManager.logDetail(LogConstants.CTX_DQP, processingException, "Sending error to client", requestID); //$NON-NLS-1$
- ResultsMessage response = new ResultsMessage(requestMsg);
+ ResultsMessage response = new ResultsMessage();
Throwable exception = this.processingException;
if (isCanceled) {
exception = addCancelCode(exception);
@@ -737,7 +744,7 @@
// Cancel Connector atomic requests
try {
- for (DataTierTupleSource connectorRequest : this.connectorInfo.values()) {
+ for (DataTierTupleSource connectorRequest : getConnectorRequests()) {
connectorRequest.cancelRequest();
}
} finally {
@@ -837,7 +844,9 @@
Collection<DataTierTupleSource> getConnectorRequests() {
- return new LinkedList<DataTierTupleSource>(this.connectorInfo.values());
+ synchronized (this.connectorInfo) {
+ return new ArrayList<DataTierTupleSource>(this.connectorInfo.values());
+ }
}
DataTierTupleSource getConnectorRequest(AtomicRequestID id) {
@@ -872,6 +881,12 @@
private void doneProducingBatches() {
this.doneProducingBatches = true;
+ //TODO: we could perform more tracking to know what source lobs are in use
+ if (this.resultsBuffer.getLobCount() == 0) {
+ for (DataTierTupleSource connectorRequest : getConnectorRequests()) {
+ connectorRequest.fullyCloseSource();
+ }
+ }
dqpCore.finishProcessing(this);
}
Copied: branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/SerializableTupleBatch.java (from rev 3506, trunk/engine/src/main/java/org/teiid/dqp/internal/process/SerializableTupleBatch.java)
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/SerializableTupleBatch.java (rev 0)
+++ branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/SerializableTupleBatch.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.dqp.internal.process;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.List;
+
+import org.teiid.client.BatchSerializer;
+import org.teiid.common.buffer.TupleBatch;
+import org.teiid.core.util.ExternalizeUtil;
+
+public class SerializableTupleBatch extends TupleBatch implements Externalizable {
+
+ private String[] types;
+
+ public SerializableTupleBatch() {
+ //for Externalizable
+ }
+
+ public SerializableTupleBatch(TupleBatch batch, String[] types) {
+ super(batch.getBeginRow(), batch.getTuples());
+ this.types = types;
+ }
+
+ @Override
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ String[] types = ExternalizeUtil.readStringArray(in);
+ this.setRowOffset(in.readInt());
+ this.setTerminationFlag(in.readBoolean());
+ this.tuples = (List)BatchSerializer.readBatch(in, types);
+ }
+
+ @Override
+ public void writeExternal(ObjectOutput out) throws IOException {
+ ExternalizeUtil.writeArray(out, types);
+ out.writeInt(this.getBeginRow());
+ out.writeBoolean(this.getTerminationFlag());
+ BatchSerializer.writeBatch(out, types, this.getTuples());
+ }
+
+}
Modified: branches/as7/engine/src/main/java/org/teiid/dqp/message/AtomicResultsMessage.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/dqp/message/AtomicResultsMessage.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/dqp/message/AtomicResultsMessage.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -22,20 +22,12 @@
package org.teiid.dqp.message;
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import java.util.List;
-import org.teiid.client.BatchSerializer;
-import org.teiid.core.util.ExternalizeUtil;
+public class AtomicResultsMessage {
-public class AtomicResultsMessage implements Externalizable {
-
private List[] results;
- private String[] dataTypes;
// Final row index in complete result set, if known
private int finalRow = -1;
@@ -53,8 +45,7 @@
public AtomicResultsMessage() {
}
- public AtomicResultsMessage(List[] results, String[] dataTypes) {
- this.dataTypes = dataTypes;
+ public AtomicResultsMessage(List[] results) {
this.results = results;
}
@@ -86,26 +77,6 @@
return results;
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- dataTypes = ExternalizeUtil.readStringArray(in);
- results = BatchSerializer.readBatch(in, dataTypes);
- finalRow = in.readInt();
- supportsImplicitClose = in.readBoolean();
- warnings = (List<Exception>)in.readObject();
- isTransactional = in.readBoolean();
- supportsCloseWithLobs = in.readBoolean();
- }
-
- public void writeExternal(ObjectOutput out) throws IOException {
- ExternalizeUtil.writeArray(out, dataTypes);
- BatchSerializer.writeBatch(out, dataTypes, results);
- out.writeInt(finalRow);
- out.writeBoolean(supportsImplicitClose);
- out.writeObject(warnings);
- out.writeBoolean(isTransactional);
- out.writeBoolean(supportsCloseWithLobs);
- }
-
public boolean isTransactional() {
return isTransactional;
}
Property changes on: branches/as7/engine/src/main/java/org/teiid/query/function/FunctionDescriptor.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/main/java/org/teiid/query/function/FunctionDescriptor.java:3149-3171
/trunk/engine/src/main/java/org/teiid/query/function/FunctionDescriptor.java:3188-3450
+ /branches/7.4.x/engine/src/main/java/org/teiid/query/function/FunctionDescriptor.java:3149-3171
/trunk/engine/src/main/java/org/teiid/query/function/FunctionDescriptor.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/main/java/org/teiid/query/function/FunctionTree.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/main/java/org/teiid/query/function/FunctionTree.java:3149-3171
/trunk/engine/src/main/java/org/teiid/query/function/FunctionTree.java:3188-3450
+ /branches/7.4.x/engine/src/main/java/org/teiid/query/function/FunctionTree.java:3149-3171
/trunk/engine/src/main/java/org/teiid/query/function/FunctionTree.java:3188-3450,3452-3506
Modified: branches/as7/engine/src/main/java/org/teiid/query/function/source/SecuritySystemFunctions.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/query/function/source/SecuritySystemFunctions.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/query/function/source/SecuritySystemFunctions.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -31,7 +31,7 @@
public class SecuritySystemFunctions {
- public static boolean hasRole(CommandContext context, Object roleName) throws FunctionExecutionException {
+ public static boolean hasRole(CommandContext context, String roleName) throws FunctionExecutionException {
SecurityFunctionEvaluator eval = context.getSecurityFunctionEvaluator();
if (eval == null) {
@@ -39,13 +39,13 @@
}
try {
- return eval.hasRole(SecurityFunctionEvaluator.DATA_ROLE, (String)roleName);
+ return eval.hasRole(SecurityFunctionEvaluator.DATA_ROLE, roleName);
} catch (TeiidComponentException err) {
throw new FunctionExecutionException(err, err.getMessage());
}
}
- public static boolean hasRole(CommandContext context, Object roleType, Object roleName) throws FunctionExecutionException {
+ public static boolean hasRole(CommandContext context, String roleType, String roleName) throws FunctionExecutionException {
SecurityFunctionEvaluator eval = context.getSecurityFunctionEvaluator();
@@ -54,7 +54,7 @@
}
try {
- return eval.hasRole((String)roleType, (String)roleName);
+ return eval.hasRole(roleType, roleName);
} catch (TeiidComponentException err) {
throw new FunctionExecutionException(err, err.getMessage());
}
Modified: branches/as7/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -105,6 +105,11 @@
} catch (IOException e) {
}
}
+
+ @Override
+ public StorageMode getStorageMode() {
+ return StorageMode.PERSISTENT;
+ }
}
public static class Resource {
Property changes on: branches/as7/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java:3149-3217
/trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java:3188-3450
+ /branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java:3149-3217
/trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java:3149-3217
/trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java:3188-3450
+ /branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java:3149-3217
/trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java:3220-3275,3340-3349
/trunk/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java:3188-3450
+ /branches/7.4.x/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java:3220-3275,3340-3349
/trunk/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java:3188-3450,3452-3506
Modified: branches/as7/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -163,7 +163,7 @@
*/
public void initialize(CommandContext context, ProcessorDataManager dataMgr, BufferManager bufferMgr) {
this.bufferMgr = bufferMgr;
- this.batchSize = bufferMgr.getProcessorBatchSize();
+ this.batchSize = bufferMgr.getProcessorBatchSize(getOutputElements());
setContext(context.clone());
this.dataMgr = new ProcessorDataManager() {
Modified: branches/as7/engine/src/main/java/org/teiid/query/processor/relational/EnhancedSortMergeJoinStrategy.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/query/processor/relational/EnhancedSortMergeJoinStrategy.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/query/processor/relational/EnhancedSortMergeJoinStrategy.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -141,6 +141,7 @@
List<?> lastTuple = null;
boolean sortedDistinct = sorted && !state.isDistinct();
int sizeHint = index.getExpectedHeight(state.getTupleBuffer().getRowCount());
+ index.setBatchInsert(sorted);
outer: while (its.hasNext()) {
//detect if sorted and distinct
List<?> originalTuple = its.nextTuple();
@@ -162,6 +163,8 @@
}
if (!sorted) {
index.compact();
+ } else {
+ index.setBatchInsert(false);
}
its.closeSource();
this.reverseIndexes = new int[elements.size()];
Modified: branches/as7/engine/src/main/java/org/teiid/query/processor/relational/NullNode.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/query/processor/relational/NullNode.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/query/processor/relational/NullNode.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -22,6 +22,9 @@
package org.teiid.query.processor.relational;
+import java.util.Collections;
+import java.util.List;
+
import org.teiid.common.buffer.TupleBatch;
import org.teiid.core.TeiidComponentException;
@@ -38,11 +41,12 @@
this.terminateBatches();
return pullBatch();
}
+
+ @Override
+ public List getOutputElements() {
+ return Collections.emptyList();
+ }
- protected void getNodeString(StringBuffer str) {
- super.getNodeString(str);
- }
-
public Object clone(){
NullNode clonedNode = new NullNode(super.getID());
super.copy(this, clonedNode);
Modified: branches/as7/engine/src/main/java/org/teiid/query/processor/relational/RelationalNode.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/query/processor/relational/RelationalNode.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/query/processor/relational/RelationalNode.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -114,7 +114,11 @@
this.getProcessingState().nodeStatistics = new RelationalNodeStatistics();
}
- this.getProcessingState().batchSize = bufferManager.getProcessorBatchSize();
+ if (getOutputElements() != null) {
+ this.getProcessingState().batchSize = bufferManager.getProcessorBatchSize(getOutputElements());
+ } else {
+ this.getProcessingState().batchSize = bufferManager.getProcessorBatchSize();
+ }
}
public CommandContext getContext() {
Modified: branches/as7/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -94,6 +94,7 @@
private String groupName;
private List<? extends Expression> schema;
private int schemaSize;
+ private int batchSize;
private ListNestedSortComparator comparator;
private TupleBuffer output;
@@ -164,6 +165,7 @@
this.groupName = groupName;
this.schema = schema;
this.schemaSize = bufferManager.getSchemaSize(this.schema);
+ this.batchSize = bufferManager.getProcessorBatchSize(this.schema);
this.comparator = new ListNestedSortComparator(cols, sortTypes);
int distinctIndex = cols.length - 1;
this.comparator.setDistinctIndex(distinctIndex);
@@ -226,7 +228,7 @@
int totalReservedBuffers = 0;
try {
- int maxRows = this.bufferManager.getProcessorBatchSize();
+ int maxRows = this.batchSize;
while(!doneReading) {
//attempt to reserve more working memory if there are additional rows available before blocking
if (workingTuples.size() >= maxRows) {
@@ -236,7 +238,7 @@
break;
}
totalReservedBuffers += reserved;
- maxRows += bufferManager.getProcessorBatchSize();
+ maxRows += this.batchSize;
}
try {
List<?> tuple = source.nextTuple();
@@ -249,7 +251,7 @@
this.collected++;
}
} catch(BlockedException e) {
- if (workingTuples.size() >= bufferManager.getProcessorBatchSize()) {
+ if (workingTuples.size() >= this.batchSize) {
break;
}
if (mode != Mode.DUP_REMOVE
Modified: branches/as7/engine/src/main/java/org/teiid/query/processor/xml/RelationalPlanExecutor.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/query/processor/xml/RelationalPlanExecutor.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/query/processor/xml/RelationalPlanExecutor.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -144,11 +144,8 @@
if (this.resultInfo.isAutoStaged() && tempTable != null) {
AlterTempTable att = new AlterTempTable(tempTable);
- int size = (Integer)this.currentRow.get(0);
- if (size > this.bufferMgr.getProcessorBatchSize() * 2) {
- //TODO: if the parent is small, then this is not necessary
- att.setIndexColumns(this.resultInfo.getFkColumns());
- }
+ //TODO: if the parent is small, then this is not necessary
+ att.setIndexColumns(this.resultInfo.getFkColumns());
this.dataManager.registerRequest(this.internalProcessor.getContext(), att, TempMetadataAdapter.TEMP_MODEL.getName(), null, 0, -1);
}
Property changes on: branches/as7/engine/src/main/java/org/teiid/query/sql/LanguageObject.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/main/java/org/teiid/query/sql/LanguageObject.java:3149-3217
/trunk/engine/src/main/java/org/teiid/query/sql/LanguageObject.java:3188-3450
+ /branches/7.4.x/engine/src/main/java/org/teiid/query/sql/LanguageObject.java:3149-3217
/trunk/engine/src/main/java/org/teiid/query/sql/LanguageObject.java:3188-3450,3452-3506
Modified: branches/as7/engine/src/main/java/org/teiid/query/tempdata/GlobalTableStoreImpl.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/query/tempdata/GlobalTableStoreImpl.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/query/tempdata/GlobalTableStoreImpl.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -290,7 +290,7 @@
if (tempTable != null) {
TempMetadataID id = tableStore.getMetadataStore().getTempGroupID(matTableName);
synchronized (id) {
- boolean clone = tempTable.getActiveReaders().get() != 0;
+ boolean clone = tempTable.getActive().get() != 0;
if (clone) {
tempTable = tempTable.clone();
}
Modified: branches/as7/engine/src/main/java/org/teiid/query/tempdata/TempTable.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/query/tempdata/TempTable.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/query/tempdata/TempTable.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -36,6 +36,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.teiid.api.exception.query.ExpressionEvaluationException;
@@ -89,6 +90,19 @@
this.addRowId = addRowId;
this.indexes = indexes;
}
+
+ @Override
+ int process() throws ExpressionEvaluationException,
+ TeiidComponentException, TeiidProcessingException {
+ tree.setBatchInsert(addRowId);
+ return super.process();
+ }
+
+ @Override
+ protected void afterCompletion() throws TeiidComponentException {
+ tree.setBatchInsert(false);
+ }
+
@Override
protected void tuplePassed(List tuple) throws BlockedException,
@@ -236,6 +250,7 @@
success = true;
} finally {
try {
+ afterCompletion();
if (!success && undoLog != null) {
undoLog.setFinal(true);
TupleSource undoTs = undoLog.createIndexedTupleSource();
@@ -259,6 +274,14 @@
return updateCount;
}
+ /**
+ *
+ * @throws TeiidComponentException
+ */
+ protected void afterCompletion() throws TeiidComponentException {
+
+ }
+
@SuppressWarnings("unused")
void success() throws TeiidComponentException, ExpressionEvaluationException, TeiidProcessingException {}
@@ -275,9 +298,9 @@
}
}
- private static AtomicInteger ID_GENERATOR = new AtomicInteger();
+ private static AtomicLong ID_GENERATOR = new AtomicLong();
- private int id = ID_GENERATOR.getAndIncrement();
+ private Long id = ID_GENERATOR.getAndIncrement();
private STree tree;
private AtomicInteger rowId;
private List<ElementSymbol> columns;
@@ -361,7 +384,7 @@
}
}
- public AtomicInteger getActiveReaders() {
+ public AtomicInteger getActive() {
return activeReaders;
}
@@ -803,13 +826,13 @@
return tid;
}
- public int getId() {
+ public Long getId() {
return id;
}
@Override
public int hashCode() {
- return id;
+ return id.hashCode();
}
@Override
@@ -821,7 +844,7 @@
return false;
}
TempTable other = (TempTable)obj;
- return id == other.id;
+ return id.equals(other.id);
}
}
\ No newline at end of file
Modified: branches/as7/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -213,7 +213,7 @@
TempTable tt = contextStore.getTempTable(att.getTempTable().toUpperCase());
Assertion.isNotNull(tt, "Table doesn't exist"); //$NON-NLS-1$
tt.setUpdatable(false);
- if (att.getIndexColumns() != null) {
+ if (att.getIndexColumns() != null && tt.getRowCount() > 2*tt.getTree().getPageSize(true)) {
tt.addIndex(att.getIndexColumns(), false);
}
return CollectionTupleSource.createUpdateCountTupleSource(0);
Modified: branches/as7/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -82,7 +82,7 @@
public class TempTableSynchronization implements Synchronization {
private String id;
- Set<Integer> existingTables = new HashSet<Integer>();
+ Set<Long> existingTables = new HashSet<Long>();
ConcurrentHashMap<String, TempTable> tables = new ConcurrentHashMap<String, TempTable>();
private List<TransactionCallback> callbacks = new LinkedList<TransactionCallback>();
@@ -131,10 +131,21 @@
@Override
public synchronized void afterCompletion(int status) {
- //TODO: cleanup tables
completed = true;
synchronizations.remove(id);
- for (TransactionCallback callback : callbacks) {
+ if (transactionMode == TransactionMode.ISOLATE_READS) {
+ for (TempTable table : tables.values()) {
+ table.getActive().decrementAndGet();
+ }
+ } else {
+ HashSet<TempTable> current = new HashSet<TempTable>(tempTables.values());
+ current.retainAll(tables.values());
+ for (TempTable table : current) {
+ table.getActive().set(0);
+ table.getTree().clearClonedFlags();
+ }
+ }
+ for (TransactionCallback callback : callbacks) {
if (status == Status.STATUS_COMMITTED) {
callback.commit();
} else {
@@ -144,6 +155,10 @@
callbacks.clear();
}
+ public boolean isCompleted() {
+ return completed;
+ }
+
@Override
public void beforeCompletion() {
@@ -307,11 +322,21 @@
if (synch != null && synch.existingTables.contains(tempTable.getId())) {
TempTable result = synch.tables.get(tempTableID);
if (result == null) {
- synch.tables.put(tempTableID, tempTable.clone());
+ synchronized (synch) {
+ if (synch.isCompleted()) {
+ throw new AssertionError("Expected active transaction"); //$NON-NLS-1$
+ }
+ if (!tempTable.getActive().compareAndSet(0, 1)) {
+ throw new TeiidProcessingException(QueryPlugin.Util.getString("TempTableStore.pending_update", tempTableID)); //$NON-NLS-1$
+ }
+ synch.tables.put(tempTableID, tempTable.clone());
+ }
}
return tempTable;
}
- }
+ } else if (tempTable.getActive().get() != 0) {
+ throw new TeiidProcessingException(QueryPlugin.Util.getString("TempTableStore.pending_update", tempTableID)); //$NON-NLS-1$
+ }
}
} else if (transactionMode == TransactionMode.ISOLATE_READS) {
TransactionContext tc = context.getTransactionContext();
@@ -320,24 +345,13 @@
if (synch != null) {
TempTable result = synch.tables.get(tempTableID);
if (result == null) {
- synch.tables.put(tempTableID, tempTable);
result = tempTable;
- result.getActiveReaders().getAndIncrement();
- TransactionCallback callback = new TransactionCallback() {
-
- @Override
- public void rollback() {
- tempTable.getActiveReaders().getAndDecrement();
- }
-
- @Override
- public void commit() {
- tempTable.getActiveReaders().getAndDecrement();
- }
- };
- if (!synch.addCallback(callback)) {
- callback.rollback();
- }
+ synchronized (synch) {
+ if (!synch.isCompleted()) {
+ synch.tables.put(tempTableID, tempTable);
+ result.getActive().getAndIncrement();
+ }
+ }
}
return result;
}
Modified: branches/as7/engine/src/main/java/org/teiid/query/util/CommandContext.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/query/util/CommandContext.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/java/org/teiid/query/util/CommandContext.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -26,6 +26,7 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Random;
@@ -78,8 +79,6 @@
private int processorBatchSize = BufferManager.DEFAULT_PROCESSOR_BATCH_SIZE;
- private int connectorBatchSize = BufferManager.DEFAULT_CONNECTOR_BATCH_SIZE;
-
private String userName;
private Serializable commandPayload;
@@ -312,20 +311,15 @@
return this.globalState.collectNodeStatistics;
}
- public int getConnectorBatchSize() {
- return this.globalState.connectorBatchSize;
- }
-
- public void setConnectorBatchSize(int connectorBatchSize) {
- this.globalState.connectorBatchSize = connectorBatchSize;
- }
-
-
+ @Override
public int getProcessorBatchSize() {
return this.globalState.processorBatchSize;
}
-
+ public int getProcessorBatchSize(List<Expression> schema) {
+ return this.globalState.bufferManager.getProcessorBatchSize(schema);
+ }
+
public void setProcessorBatchSize(int processorBatchSize) {
this.globalState.processorBatchSize = processorBatchSize;
}
Modified: branches/as7/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- branches/as7/engine/src/main/resources/org/teiid/query/i18n.properties 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/main/resources/org/teiid/query/i18n.properties 2011-09-29 16:46:38 UTC (rev 3507)
@@ -791,6 +791,7 @@
RulePlanJoins.cantSatisfy=Join region with unsatisfied access patterns cannot be satisfied by the join criteria, Access patterns: {0}
TempTableStore.table_exist_error=Temporary table "{0}" already exists.
TempTableStore.table_doesnt_exist_error=Temporary table "{0}" does not exist.
+TempTableStore.pending_update=Table {0} is locked by pending transaction update.
XMLQueryPlanner.cannot_plan=Cannot create a query for MappingClass with user criteria {0}
XMLQueryPlanner.invalid_relationship=Conjunct "{0}" has no relationship with target context {1}.
Modified: branches/as7/engine/src/test/java/org/teiid/common/buffer/BufferManagerFactory.java
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/common/buffer/BufferManagerFactory.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/test/java/org/teiid/common/buffer/BufferManagerFactory.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -22,9 +22,10 @@
package org.teiid.common.buffer;
-import org.teiid.common.buffer.BufferManager;
import org.teiid.common.buffer.impl.BufferManagerImpl;
+import org.teiid.common.buffer.impl.FileStoreCache;
import org.teiid.common.buffer.impl.MemoryStorageManager;
+import org.teiid.common.buffer.impl.SplittableStorageManager;
import org.teiid.core.TeiidComponentException;
@@ -81,12 +82,18 @@
public static BufferManagerImpl initBufferManager(BufferManagerImpl bufferManager) {
try {
bufferManager.initialize();
- } catch (TeiidComponentException e) {
+ MemoryStorageManager storageManager = new MemoryStorageManager();
+ SplittableStorageManager ssm = new SplittableStorageManager(storageManager);
+ ssm.setMaxFileSizeDirect(MemoryStorageManager.MAX_FILE_SIZE);
+ FileStoreCache fsc = new FileStoreCache();
+ fsc.setMaxBufferSpace(Runtime.getRuntime().maxMemory()/4);
+ fsc.setStorageManager(ssm);
+ fsc.initialize();
+ bufferManager.setCache(fsc);
+ return bufferManager;
+ } catch (TeiidComponentException e) {
throw new RuntimeException(e);
}
-
- bufferManager.setStorageManager(new MemoryStorageManager());
- return bufferManager;
}
}
Modified: branches/as7/engine/src/test/java/org/teiid/common/buffer/TestLobManager.java
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/common/buffer/TestLobManager.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/test/java/org/teiid/common/buffer/TestLobManager.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -28,8 +28,10 @@
import java.io.StringReader;
import java.nio.charset.Charset;
import java.util.Arrays;
+import java.util.List;
import org.junit.Test;
+import org.teiid.common.buffer.LobManager.ReferenceMode;
import org.teiid.common.buffer.impl.BufferManagerImpl;
import org.teiid.core.types.BlobImpl;
import org.teiid.core.types.BlobType;
@@ -65,9 +67,11 @@
}));
- LobManager lobManager = new LobManager();
- lobManager.updateReferences(new int[] {0,1}, Arrays.asList(clob, blob));
- lobManager.persist(fs);
+ LobManager lobManager = new LobManager(new int[] {0, 1}, fs);
+ lobManager.setMaxMemoryBytes(4);
+ List<Streamable<? extends Object>> tuple = Arrays.asList(clob, blob);
+ lobManager.updateReferences(tuple, ReferenceMode.CREATE);
+ lobManager.persist();
Streamable<?>lob = lobManager.getLobReference(clob.getReferenceStreamId());
assertTrue(lob.getClass().isAssignableFrom(ClobType.class));
@@ -80,6 +84,10 @@
BlobType blobRead = (BlobType)lob;
assertTrue(Arrays.equals(ObjectConverterUtil.convertToByteArray(blob.getBinaryStream()), ObjectConverterUtil.convertToByteArray(blobRead.getBinaryStream())));
+ lobManager.updateReferences(tuple, ReferenceMode.REMOVE);
+
+ assertEquals(0, lobManager.getLobCount());
+
}
}
Modified: branches/as7/engine/src/test/java/org/teiid/common/buffer/TestSTree.java
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/common/buffer/TestSTree.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/test/java/org/teiid/common/buffer/TestSTree.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -79,7 +79,7 @@
@Test public void testOrderedInsert() throws TeiidComponentException {
BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
- bm.setProcessorBatchSize(16);
+ bm.setProcessorBatchSize(4);
ElementSymbol e1 = new ElementSymbol("x");
e1.setType(Integer.class);
@@ -100,5 +100,33 @@
}
}
-
+
+ /**
+ * Forces the logic through several compaction cycles by using large strings
+ * @throws TeiidComponentException
+ */
+ @Test public void testCompaction() throws TeiidComponentException {
+ BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
+ bm.setProcessorBatchSize(32);
+ bm.setMaxReserveKB(0);//force all to disk
+ bm.initialize();
+
+ ElementSymbol e1 = new ElementSymbol("x");
+ e1.setType(String.class);
+ List<ElementSymbol> elements = Arrays.asList(e1);
+ STree map = bm.createSTree(elements, "1", 1);
+
+ int size = 1000;
+
+ for (int i = 0; i < size; i++) {
+ assertNull(map.insert(Arrays.asList(new String(new byte[1000])), InsertMode.ORDERED, size));
+ assertEquals(i + 1, map.getRowCount());
+ }
+
+ for (int i = 0; i < size; i++) {
+ assertNotNull(map.remove(Arrays.asList(new String(new byte[1000]))));
+ }
+
+ }
+
}
Modified: branches/as7/engine/src/test/java/org/teiid/common/buffer/TestTupleBuffer.java
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/common/buffer/TestTupleBuffer.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/test/java/org/teiid/common/buffer/TestTupleBuffer.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -30,60 +30,18 @@
import javax.sql.rowset.serial.SerialClob;
import org.junit.Test;
-import org.mockito.Mockito;
-import org.teiid.core.TeiidComponentException;
+import org.teiid.common.buffer.BufferManager.TupleSourceType;
import org.teiid.core.types.ClobType;
import org.teiid.core.types.DataTypeManager;
import org.teiid.query.sql.symbol.ElementSymbol;
-
public class TestTupleBuffer {
- public static final class FakeBatchManager implements BatchManager {
- @Override
- public void remove() {
-
- }
-
- @Override
- public ManagedBatch createManagedBatch(final TupleBatch batch, boolean softCache)
- throws TeiidComponentException {
- return new ManagedBatch() {
-
- @Override
- public void remove() {
-
- }
-
- @Override
- public TupleBatch getBatch(boolean cache, String[] types)
- throws TeiidComponentException {
- return batch;
- }
-
- @Override
- public void setPrefersMemory(boolean prefers) {
-
- }
-
- @Override
- public CleanupHook getCleanupHook() {
- return null;
- }
- };
- }
-
- @Override
- public FileStore createStorage(String prefix) {
- return Mockito.mock(FileStore.class);
- }
- }
-
@Test public void testForwardOnly() throws Exception {
ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$
x.setType(DataTypeManager.DefaultDataClasses.INTEGER);
List<ElementSymbol> schema = Arrays.asList(x);
- TupleBuffer tb = new TupleBuffer(new FakeBatchManager(), "x", schema, null, 32); //$NON-NLS-1$
+ TupleBuffer tb = BufferManagerFactory.getStandaloneBufferManager().createTupleBuffer(schema, "x", TupleSourceType.PROCESSOR); //$NON-NLS-1$
tb.setForwardOnly(true);
tb.addTuple(Arrays.asList(1));
TupleBatch batch = tb.getBatch(1);
@@ -106,7 +64,8 @@
ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$
x.setType(DataTypeManager.DefaultDataClasses.CLOB);
List<ElementSymbol> schema = Arrays.asList(x);
- TupleBuffer tb = new TupleBuffer(new FakeBatchManager(), "x", schema, LobManager.getLobIndexes(schema), 32); //$NON-NLS-1$
+ TupleBuffer tb = BufferManagerFactory.getStandaloneBufferManager().createTupleBuffer(schema, "x", TupleSourceType.PROCESSOR); //$NON-NLS-1$
+ tb.setInlineLobs(false);
ClobType c = new ClobType(new SerialClob(new char[0]));
TupleBatch batch = new TupleBatch(1, new List[] {Arrays.asList(c)});
tb.addTupleBatch(batch, false);
Copied: branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockBitSetTree.java (from rev 3506, trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockBitSetTree.java)
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockBitSetTree.java (rev 0)
+++ branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockBitSetTree.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+ package org.teiid.common.buffer.impl;
+
+import static org.junit.Assert.*;
+
+import java.util.BitSet;
+import java.util.Random;
+
+import org.junit.Test;
+
+public class TestBlockBitSetTree {
+
+ @Test public void testBitsSet() {
+ BlockBitSetTree bst = new BlockBitSetTree((1 << 20) -1, new TestBlockClosedLongIntHashTable.DummyBlockManager());
+ bst.set(1, true);
+ bst.set(100, true);
+ bst.set(10000, true);
+ bst.set(1000000, true);
+ assertEquals(4, bst.getBitsSet());
+ bst.set(1, false);
+ assertEquals(3, bst.getBitsSet());
+ assertFalse(bst.get(1));
+ }
+
+ @Test public void testNextClearSet() {
+ BlockBitSetTree bst = new BlockBitSetTree((1 << 20) -1, new TestBlockClosedLongIntHashTable.DummyBlockManager());
+ BitSet bst1 = new BitSet();
+ Random r = new Random(1);
+ for (int i = 0; i < 1000; i++) {
+ int rand = r.nextInt() & bst.getMaxIndex();
+ bst.set(rand, true);
+ bst1.set(rand, true);
+ assertTrue(bst.get(rand));
+ assertEquals(bst1.nextSetBit(rand), bst.nextSetBit(rand));
+ assertEquals(String.valueOf(i), bst1.nextSetBit(rand), bst.nextSetBit(rand));
+ }
+
+ for (int i = 0; i < 10000; i++) {
+ int rand = r.nextInt() & bst.getMaxIndex();
+ assertEquals(bst1.nextClearBit(rand), bst.nextClearBit(rand));
+ assertEquals(bst1.nextSetBit(rand), bst.nextSetBit(rand));
+ }
+ }
+
+}
Copied: branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockClosedLongIntHashTable.java (from rev 3506, trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockClosedLongIntHashTable.java)
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockClosedLongIntHashTable.java (rev 0)
+++ branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockClosedLongIntHashTable.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer.impl;
+
+import static org.junit.Assert.*;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Random;
+
+import org.junit.Test;
+import org.teiid.common.buffer.impl.FileStoreCache.BlockInfo;
+
+public class TestBlockClosedLongIntHashTable {
+
+ public static final class DummyBlockManager implements BlockManager {
+ List<BlockInfo> blocks = new ArrayList<BlockInfo>();
+
+ @Override
+ public int getInode() {
+ return 0;
+ }
+
+ @Override
+ public void updateBlock(BlockInfo block) {
+
+ }
+
+ @Override
+ public void free() {
+ blocks.clear();
+ }
+
+ @Override
+ public BlockInfo getBlock(int index) {
+ BlockInfo block = blocks.get(index);
+ block.buf.rewind();
+ return block;
+ }
+
+ @Override
+ public void freeBlock(int index) {
+ blocks.remove(index);
+ }
+
+ @Override
+ public BlockInfo allocateBlock(int index) {
+ assertEquals(index, blocks.size());
+ ByteBuffer result = ByteBuffer.wrap(new byte[FileStoreCache.BLOCK_SIZE]);
+ blocks.add(new BlockInfo(false, result, index, -1));
+ return blocks.get(blocks.size() - 1);
+ }
+ }
+
+ @Test public void testAgainstHashMap() {
+ BlockClosedLongIntHashTable table = new BlockClosedLongIntHashTable(new DummyBlockManager());
+ HashMap<Long, Integer> table1 = new HashMap<Long, Integer>(16);
+ for (long i = 1; i < 200000; i++) {
+ table.put(i, (int)i);
+ table1.put(i, (int)i);
+ }
+ Random r = new Random(0);
+ for (int i = 1; i < 2000000; i++) {
+ long toRemove = r.nextInt(i);
+ boolean removed = table.remove(toRemove) != BlockClosedLongIntHashTable.EMPTY;
+ assertEquals(table1.remove(toRemove) != null, removed);
+ }
+ }
+
+}
Modified: branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStorageManager.java
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStorageManager.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStorageManager.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -25,11 +25,10 @@
import static org.junit.Assert.*;
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.io.RandomAccessFile;
import java.util.Arrays;
-import java.util.Map;
import java.util.Random;
import org.junit.Test;
@@ -41,12 +40,9 @@
@SuppressWarnings("nls")
public class TestFileStorageManager {
- public FileStorageManager getStorageManager(Integer maxFileSize, Integer openFiles, String dir) throws TeiidComponentException {
+ public FileStorageManager getStorageManager(Integer openFiles, String dir) throws TeiidComponentException {
FileStorageManager sm = new FileStorageManager();
sm.setStorageDirectory(UnitTestUtil.getTestScratchPath() + (dir != null ? File.separator + dir : "")); //$NON-NLS-1$
- if (maxFileSize != null) {
- sm.setMaxFileSizeDirect(maxFileSize);
- }
if (openFiles != null) {
sm.setMaxOpenFiles(openFiles);
}
@@ -55,7 +51,7 @@
}
@Test public void testWrite() throws Exception {
- FileStorageManager sm = getStorageManager(null, null, null);
+ FileStorageManager sm = getStorageManager(null, null);
String tsID = "0"; //$NON-NLS-1$
FileStore store = sm.createFileStore(tsID);
writeBytes(store);
@@ -64,27 +60,8 @@
assertEquals(0, sm.getUsedBufferSpace());
}
- @Test public void testCreatesSpillFiles() throws Exception {
- FileStorageManager sm = getStorageManager(1024, null, null); // 1KB
- String tsID = "0"; //$NON-NLS-1$
- // Add one batch
- FileStore store = sm.createFileStore(tsID);
- writeBytes(store);
-
- Map<File, RandomAccessFile> cache = sm.getFileCache();
- assertEquals(1, cache.size());
-
- writeBytes(store);
-
- assertEquals(2, cache.size());
-
- store.remove();
-
- assertEquals(0, cache.size());
- }
-
- @Test(expected=TeiidComponentException.class) public void testMaxSpace() throws Exception {
- FileStorageManager sm = getStorageManager(null, null, null);
+ @Test(expected=IOException.class) public void testMaxSpace() throws Exception {
+ FileStorageManager sm = getStorageManager(null, null);
sm.setMaxBufferSpace(1);
String tsID = "0"; //$NON-NLS-1$
// Add one batch
@@ -93,7 +70,7 @@
}
@Test public void testFlush() throws Exception {
- FileStorageManager sm = getStorageManager(null, null, null);
+ FileStorageManager sm = getStorageManager(null, null);
FileStore store = sm.createFileStore("0");
FileStoreOutputStream fsos = store.createOutputStream(2);
fsos.write(new byte[3]);
@@ -104,19 +81,19 @@
static Random r = new Random();
- private void writeBytes(FileStore store)
- throws TeiidComponentException {
+ static void writeBytes(FileStore store)
+ throws IOException {
byte[] bytes = new byte[2048];
r.nextBytes(bytes);
- long start = store.write(bytes, 0, bytes.length);
+ long start = store.getLength();
+ store.write(bytes, 0, bytes.length);
byte[] bytesRead = new byte[2048];
store.readFully(start, bytesRead, 0, bytesRead.length);
assertTrue(Arrays.equals(bytes, bytesRead));
}
-
@Test public void testWritingMultipleFiles() throws Exception {
- FileStorageManager sm = getStorageManager(1024, null, null);
+ FileStorageManager sm = getStorageManager(null, null);
String tsID = "0"; //$NON-NLS-1$
// Add one batch
FileStore store = sm.createFileStore(tsID);
Copied: branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStoreCache.java (from rev 3506, trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStoreCache.java)
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStoreCache.java (rev 0)
+++ branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStoreCache.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer.impl;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.junit.Test;
+import org.teiid.common.buffer.CacheEntry;
+import org.teiid.common.buffer.Serializer;
+import org.teiid.core.util.UnitTestUtil;
+
+public class TestFileStoreCache {
+
+ private final class SimpleSerializer implements Serializer<Integer> {
+ @Override
+ public Integer deserialize(ObjectInputStream ois)
+ throws IOException, ClassNotFoundException {
+ Integer result = ois.readInt();
+ for (int i = 0; i < result; i++) {
+ assertEquals(i, ois.readInt());
+ }
+ return result;
+ }
+
+ @Override
+ public Long getId() {
+ return 1l;
+ }
+
+ @Override
+ public void serialize(Integer obj, ObjectOutputStream oos)
+ throws IOException {
+ oos.writeInt(obj);
+ for (int i = 0; i < obj; i++) {
+ oos.writeInt(i);
+ }
+ }
+
+ @Override
+ public boolean useSoftCache() {
+ return false;
+ }
+ }
+
+ @Test public void testAddGetMultiBlock() throws Exception {
+ FileStoreCache fsc = new FileStoreCache();
+ fsc.setMaxBufferSpace(1 << 28);
+ SplittableStorageManager ssm = new SplittableStorageManager(new MemoryStorageManager());
+ ssm.setMaxFileSizeDirect(MemoryStorageManager.MAX_FILE_SIZE);
+ fsc.setStorageManager(ssm);
+ fsc.initialize();
+
+ UnitTestUtil.enableTraceLogging("org.teiid"); //$NON-NLS-1$
+
+ CacheEntry ce = new CacheEntry(2l);
+ Serializer<Integer> s = new SimpleSerializer();
+ fsc.createCacheGroup(s.getId());
+ Integer cacheObject = Integer.valueOf(2);
+ ce.setObject(cacheObject);
+ fsc.add(ce, s);
+
+ ce = fsc.get(2l, s);
+ assertEquals(cacheObject, ce.getObject());
+
+ //test something that exceeds the direct inode data blocks
+ ce = new CacheEntry(3l);
+ cacheObject = Integer.valueOf(80000);
+ ce.setObject(cacheObject);
+ fsc.add(ce, s);
+
+ ce = fsc.get(3l, s);
+ assertEquals(cacheObject, ce.getObject());
+
+ fsc.removeCacheGroup(1l);
+
+ assertEquals(0, fsc.getDataBlocksInUse());
+ assertEquals(0, fsc.getInodesInUse());
+
+ //test something that exceeds the indirect inode data blocks
+ ce = new CacheEntry(3l);
+ fsc.createCacheGroup(s.getId());
+ cacheObject = Integer.valueOf(5000000);
+ ce.setObject(cacheObject);
+ fsc.add(ce, s);
+
+ ce = fsc.get(3l, s);
+ assertEquals(cacheObject, ce.getObject());
+
+ fsc.removeCacheGroup(1l);
+
+ assertEquals(0, fsc.getDataBlocksInUse());
+ assertEquals(0, fsc.getInodesInUse());
+ }
+
+}
Modified: branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestSizeUtility.java
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestSizeUtility.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestSizeUtility.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -34,7 +34,6 @@
import java.util.List;
import org.junit.Test;
-import org.teiid.common.buffer.TupleBatch;
public class TestSizeUtility {
@@ -43,7 +42,7 @@
}
public void helpTestGetSize(Object obj, long expectedSize) {
- long actualSize = new SizeUtility().getSize(obj, true, false);
+ long actualSize = new SizeUtility(null).getSize(obj, true, false);
assertEquals("Got unexpected size: ", expectedSize, actualSize); //$NON-NLS-1$
}
@@ -99,18 +98,6 @@
helpTestGetSize("abcdefghij", 64); //$NON-NLS-1$
}
- public void XtestGetSizeLongString() {
- // There is no clear way of figuring out the actual size of a string that is created
- // from a StringBuffer because the buffer can sometimes be twice as big as the actual length of the string
- // Since the data comin from the connector is not created this way, this test is an inaccurate setup
- int size = 10000;
- StringBuffer str = new StringBuffer();
- for(int i=0; i<size; i++) {
- str.append("a"); //$NON-NLS-1$
- }
- helpTestGetSize(str.toString(), size+3);
- }
-
@Test public void testGetSizeRow1() {
List<Object> row = new ArrayList<Object>(1);
row.add(new Integer(0));
@@ -176,9 +163,7 @@
String[] types = {"string", "integer", "boolean", "double", "string", "integer"}; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ //$NON-NLS-5$//$NON-NLS-6$
- TupleBatch tb = new TupleBatch(1, expected);
- tb.setDataTypes(types);
- long actualSize = new SizeUtility().getBatchSize(tb);
+ long actualSize = new SizeUtility(types).getBatchSize(Arrays.asList(expected));
assertEquals("Got unexpected size: ", 2667, actualSize); //$NON-NLS-1$
}
Copied: branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestSplittableStorageManager.java (from rev 3506, trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestSplittableStorageManager.java)
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestSplittableStorageManager.java (rev 0)
+++ branches/as7/engine/src/test/java/org/teiid/common/buffer/impl/TestSplittableStorageManager.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer.impl;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.teiid.common.buffer.FileStore;
+
+public class TestSplittableStorageManager {
+
+ @Test public void testCreatesSpillFiles() throws Exception {
+ MemoryStorageManager msm = new MemoryStorageManager();
+ SplittableStorageManager ssm = new SplittableStorageManager(msm);
+ ssm.setMaxFileSizeDirect(2048);
+ String tsID = "0"; //$NON-NLS-1$
+ // Add one batch
+ FileStore store = ssm.createFileStore(tsID);
+ TestFileStorageManager.writeBytes(store);
+
+ assertEquals(1, msm.getCreated());
+
+ TestFileStorageManager.writeBytes(store);
+
+ assertEquals(2, msm.getCreated());
+
+ store.setLength(10000);
+
+ assertEquals(5, msm.getCreated());
+
+ store.setLength(100);
+
+ assertEquals(4, msm.getRemoved());
+
+ store.remove();
+
+ assertEquals(5, msm.getRemoved());
+ }
+
+ @Test public void testTruncate() throws Exception {
+ MemoryStorageManager msm = new MemoryStorageManager();
+ SplittableStorageManager ssm = new SplittableStorageManager(msm);
+ ssm.setMaxFileSizeDirect(2048);
+ String tsID = "0"; //$NON-NLS-1$
+ // Add one batch
+ FileStore store = ssm.createFileStore(tsID);
+ TestFileStorageManager.writeBytes(store);
+
+ assertEquals(1, msm.getCreated());
+
+ TestFileStorageManager.writeBytes(store);
+
+ assertEquals(2, msm.getCreated());
+
+ store.setLength(100);
+
+ assertEquals(1, msm.getRemoved());
+
+ }
+
+}
Modified: branches/as7/engine/src/test/java/org/teiid/dqp/internal/process/TestCachedResults.java
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/dqp/internal/process/TestCachedResults.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/test/java/org/teiid/dqp/internal/process/TestCachedResults.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -23,7 +23,6 @@
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
@@ -33,8 +32,8 @@
import org.teiid.cache.Cache;
import org.teiid.cache.DefaultCache;
import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.BufferManager.TupleSourceType;
import org.teiid.common.buffer.BufferManagerFactory;
-import org.teiid.common.buffer.TestTupleBuffer.FakeBatchManager;
import org.teiid.common.buffer.TupleBuffer;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.UnitTestUtil;
@@ -62,7 +61,7 @@
ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$
x.setType(DataTypeManager.DefaultDataClasses.INTEGER);
List<ElementSymbol> schema = Arrays.asList(x);
- TupleBuffer tb = new TupleBuffer(new FakeBatchManager(), "x", schema, null, 4); //$NON-NLS-1$
+ TupleBuffer tb = BufferManagerFactory.getStandaloneBufferManager().createTupleBuffer(schema, "x", TupleSourceType.PROCESSOR); //$NON-NLS-1$
tb.setForwardOnly(false);
tb.addTuple(Arrays.asList(1));
Modified: branches/as7/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -25,6 +25,7 @@
import static org.junit.Assert.*;
import java.sql.ResultSet;
+import java.util.HashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@@ -35,6 +36,8 @@
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
+import org.teiid.adminapi.DataPolicy;
+import org.teiid.adminapi.impl.DataPolicyMetadata;
import org.teiid.api.exception.query.QueryResolverException;
import org.teiid.cache.CacheConfiguration;
import org.teiid.cache.DefaultCacheFactory;
@@ -104,6 +107,9 @@
DQPWorkContext context = RealMetadataFactory.buildWorkContext(RealMetadataFactory.createTransformationMetadata(RealMetadataFactory.exampleBQTCached().getMetadataStore(), "bqt"));
context.getVDB().getModel("BQT3").setVisible(false); //$NON-NLS-1$
context.getVDB().getModel("VQT").setVisible(false); //$NON-NLS-1$
+ HashMap<String, DataPolicy> policies = new HashMap<String, DataPolicy>();
+ policies.put("foo", new DataPolicyMetadata());
+ context.setPolicies(policies);
ConnectorManagerRepository repo = Mockito.mock(ConnectorManagerRepository.class);
context.getVDB().addAttchment(ConnectorManagerRepository.class, repo);
@@ -112,7 +118,9 @@
@Override
public BufferManager getBufferManager() {
- return BufferManagerFactory.createBufferManager();
+ BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
+ bm.setInlineLobs(false);
+ return bm;
}
};
core = new DQPCore();
@@ -124,6 +132,9 @@
config = new DQPConfiguration();
config.setMaxActivePlans(1);
config.setUserRequestSourceConcurrency(2);
+ DefaultAuthorizationValidator daa = new DefaultAuthorizationValidator();
+ daa.setPolicyDecider(new DataRolePolicyDecider());
+ config.setAuthorizationValidator(daa);
core.start(config);
core.getPrepPlanCache().setModTime(1);
core.getRsCache().setBufferManager(bs.getBufferManager());
@@ -151,6 +162,20 @@
@Test public void testRequest1() throws Exception {
helpExecute("SELECT IntKey FROM BQT1.SmallA", "a"); //$NON-NLS-1$ //$NON-NLS-2$
}
+
+ @Test public void testHasRole() throws Exception {
+ String sql = "SELECT hasRole('foo')"; //$NON-NLS-1$
+ String userName = "logon"; //$NON-NLS-1$
+ ResultsMessage rm = helpExecute(sql, userName);
+ assertTrue((Boolean)rm.getResults()[0].get(0));
+ }
+
+ @Test public void testNotHasRole() throws Exception {
+ String sql = "SELECT hasRole('bar')"; //$NON-NLS-1$
+ String userName = "logon"; //$NON-NLS-1$
+ ResultsMessage rm = helpExecute(sql, userName);
+ assertFalse((Boolean)rm.getResults()[0].get(0));
+ }
@Test public void testUser1() throws Exception {
String sql = "SELECT IntKey FROM BQT1.SmallA WHERE user() = 'logon'"; //$NON-NLS-1$
@@ -277,8 +302,8 @@
}
@Test public void testBufferLimit() throws Exception {
- //the sql should return 100 rows
- String sql = "SELECT A.IntKey FROM BQT1.SmallA as A, BQT1.SmallA as B"; //$NON-NLS-1$
+ //the sql should return 400 rows
+ String sql = "SELECT A.IntKey FROM BQT1.SmallA as A, BQT1.SmallA as B, (select intkey from BQT1.SmallA limit 4) as C"; //$NON-NLS-1$
String userName = "1"; //$NON-NLS-1$
String sessionid = "1"; //$NON-NLS-1$
@@ -286,31 +311,33 @@
reqMsg.setCursorType(ResultSet.TYPE_FORWARD_ONLY);
DQPWorkContext.getWorkContext().getSession().setSessionId(sessionid);
DQPWorkContext.getWorkContext().getSession().setUserName(userName);
- ((BufferManagerImpl)core.getBufferManager()).setProcessorBatchSize(2);
+ ((BufferManagerImpl)core.getBufferManager()).setProcessorBatchSize(1);
Future<ResultsMessage> message = core.executeRequest(reqMsg.getExecutionId(), reqMsg);
ResultsMessage rm = message.get(500000, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
- assertEquals(2, rm.getResults().length);
+
+ int rowsPerBatch = 8;
+ assertEquals(rowsPerBatch, rm.getResults().length);
RequestWorkItem item = core.getRequestWorkItem(DQPWorkContext.getWorkContext().getRequestID(reqMsg.getExecutionId()));
- message = core.processCursorRequest(reqMsg.getExecutionId(), 3, 2);
+ message = core.processCursorRequest(reqMsg.getExecutionId(), 9, rowsPerBatch);
rm = message.get(500000, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
- assertEquals(2, rm.getResults().length);
+ assertEquals(rowsPerBatch, rm.getResults().length);
//ensure that we are idle
for (int i = 0; i < 10 && item.getThreadState() != ThreadState.IDLE; i++) {
Thread.sleep(100);
}
assertEquals(ThreadState.IDLE, item.getThreadState());
- assertTrue(item.resultsBuffer.getManagedRowCount() <= 46);
+ assertTrue(item.resultsBuffer.getManagedRowCount() <= rowsPerBatch*23);
//pull the rest of the results
for (int j = 0; j < 48; j++) {
item = core.getRequestWorkItem(DQPWorkContext.getWorkContext().getRequestID(reqMsg.getExecutionId()));
- message = core.processCursorRequest(reqMsg.getExecutionId(), j * 2 + 5, 2);
+ message = core.processCursorRequest(reqMsg.getExecutionId(), (j + 2) * rowsPerBatch + 1, rowsPerBatch);
rm = message.get(5000, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
- assertEquals(2, rm.getResults().length);
+ assertEquals(rowsPerBatch, rm.getResultsList().size());
}
}
@@ -324,11 +351,11 @@
reqMsg.setCursorType(ResultSet.TYPE_FORWARD_ONLY);
DQPWorkContext.getWorkContext().getSession().setSessionId(sessionid);
DQPWorkContext.getWorkContext().getSession().setUserName(userName);
- ((BufferManagerImpl)core.getBufferManager()).setProcessorBatchSize(2);
+ ((BufferManagerImpl)core.getBufferManager()).setProcessorBatchSize(1);
Future<ResultsMessage> message = core.executeRequest(reqMsg.getExecutionId(), reqMsg);
ResultsMessage rm = message.get(500000, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
- assertEquals(2, rm.getResults().length);
+ assertEquals(8, rm.getResultsList().size());
RequestWorkItem item = core.getRequestWorkItem(DQPWorkContext.getWorkContext().getRequestID(reqMsg.getExecutionId()));
assertEquals(100, item.resultsBuffer.getRowCount());
}
Modified: branches/as7/engine/src/test/java/org/teiid/dqp/service/AutoGenDataService.java
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/dqp/service/AutoGenDataService.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/test/java/org/teiid/dqp/service/AutoGenDataService.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -95,7 +95,7 @@
results = new List[] {Arrays.asList(1)};
}
- final AtomicResultsMessage msg = ConnectorWorkItem.createResultsMessage(results, projectedSymbols);
+ final AtomicResultsMessage msg = ConnectorWorkItem.createResultsMessage(results);
msg.setFinalRow(rows);
return new ConnectorWork() {
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/function/TestFunction.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/function/TestFunction.java:3281-3325
/trunk/engine/src/test/java/org/teiid/query/function/TestFunction.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/function/TestFunction.java:3281-3325
/trunk/engine/src/test/java/org/teiid/query/function/TestFunction.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/function/TestFunctionTree.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/function/TestFunctionTree.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/function/TestFunctionTree.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/function/TestFunctionTree.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/function/TestFunctionTree.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/function/TestResolvedFunctions.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/function/TestResolvedFunctions.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/function/TestResolvedFunctions.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/function/TestResolvedFunctions.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/function/TestResolvedFunctions.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestAccessPatterns.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestAccessPatterns.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestAccessPatterns.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestAccessPatterns.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestAccessPatterns.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java:3149-3217,3220-3275
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java:3149-3217,3220-3275
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestAnsiJoinPushdown.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestAnsiJoinPushdown.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestAnsiJoinPushdown.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestAnsiJoinPushdown.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestAnsiJoinPushdown.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestBatchedUpdatePlanner.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestBatchedUpdatePlanner.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestBatchedUpdatePlanner.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestBatchedUpdatePlanner.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestBatchedUpdatePlanner.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java:3149-3217,3220-3275
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java:3149-3217,3220-3275
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestExpressionsInGroupBy.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestExpressionsInGroupBy.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestExpressionsInGroupBy.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestExpressionsInGroupBy.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestExpressionsInGroupBy.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestInlineView.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestInlineView.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestInlineView.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestInlineView.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestInlineView.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestJoinOptimization.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestJoinOptimization.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestJoinOptimization.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestJoinOptimization.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestJoinOptimization.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestJoinPushdownRestrictions.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestJoinPushdownRestrictions.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestJoinPushdownRestrictions.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestJoinPushdownRestrictions.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestJoinPushdownRestrictions.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java:3149-3217,3220-3275
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java:3149-3217,3220-3275
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestOptionalJoins.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestOptionalJoins.java:3149-3217,3220-3275
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptionalJoins.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestOptionalJoins.java:3149-3217,3220-3275
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptionalJoins.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestPartitionedJoinPlanning.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestPartitionedJoinPlanning.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestPartitionedJoinPlanning.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestPartitionedJoinPlanning.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestPartitionedJoinPlanning.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestRuleRaiseNull.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleRaiseNull.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestRuleRaiseNull.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleRaiseNull.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestRuleRaiseNull.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestRuleRemoveSorts.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleRemoveSorts.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestRuleRemoveSorts.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleRemoveSorts.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestRuleRemoveSorts.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestSortOptimization.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestSortOptimization.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestSortOptimization.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestSortOptimization.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestSortOptimization.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestStoredProcedurePlanning.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestStoredProcedurePlanning.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestStoredProcedurePlanning.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestStoredProcedurePlanning.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestStoredProcedurePlanning.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java:3149-3217,3281-3325
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java:3149-3217,3281-3325
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/TestUnionPlanning.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestUnionPlanning.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestUnionPlanning.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestUnionPlanning.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/TestUnionPlanning.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/optimizer/relational/TestAliasGenerator.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/relational/TestAliasGenerator.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestAliasGenerator.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/relational/TestAliasGenerator.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestAliasGenerator.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/processor/FakeDataManager.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/FakeDataManager.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/FakeDataManager.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/FakeDataManager.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/FakeDataManager.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/processor/FakeDataStore.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/FakeDataStore.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/FakeDataStore.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/FakeDataStore.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/FakeDataStore.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java:3149-3217,3220-3275
/trunk/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java:3149-3217,3220-3275
/trunk/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/processor/TestJoinWithFunction.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestJoinWithFunction.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestJoinWithFunction.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestJoinWithFunction.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestJoinWithFunction.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/processor/TestOptionalJoins.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestOptionalJoins.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestOptionalJoins.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestOptionalJoins.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestOptionalJoins.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/processor/TestOrderByProcessing.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestOrderByProcessing.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestOrderByProcessing.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestOrderByProcessing.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestOrderByProcessing.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/processor/TestProcedureRelational.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestProcedureRelational.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestProcedureRelational.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestProcedureRelational.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestProcedureRelational.java:3188-3450,3452-3506
Modified: branches/as7/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -365,7 +365,6 @@
props.setProperty("soap_port", "12345"); //$NON-NLS-1$ //$NON-NLS-2$
CommandContext context = new CommandContext("0", "test", "user", null, "myvdb", 1, props, DEBUG); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
context.setProcessorBatchSize(BufferManager.DEFAULT_PROCESSOR_BATCH_SIZE);
- context.setConnectorBatchSize(BufferManager.DEFAULT_CONNECTOR_BATCH_SIZE);
context.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
context.setPreparedPlanCache(new SessionAwareCache<PreparedPlan>());
return context;
@@ -1080,7 +1079,6 @@
CommandContext context = createCommandContext();
context.setProcessorBatchSize(2);
- context.setConnectorBatchSize(2);
context.setMetadata(RealMetadataFactory.example1Cached());
// Plan query
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java:3149-3217,3220-3275
/trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java:3149-3217,3220-3275
/trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java:3149-3217,3220-3275,3281-3325,3340-3349
/trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java:3149-3217,3220-3275,3281-3325,3340-3349
/trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/processor/TestSecurityFunctions.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSecurityFunctions.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestSecurityFunctions.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSecurityFunctions.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestSecurityFunctions.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/processor/TestSetProcessing.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSetProcessing.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestSetProcessing.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSetProcessing.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestSetProcessing.java:3188-3450,3452-3506
Modified: branches/as7/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/query/processor/TestTempTables.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/test/java/org/teiid/query/processor/TestTempTables.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -135,6 +135,34 @@
execute("select * from x", new List[] {});
}
+ @Test public void testCommitExistingRemoved() throws Exception {
+ execute("create local temporary table x (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
+ setupTransaction(Connection.TRANSACTION_SERIALIZABLE);
+ execute("drop table x", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
+ synch.afterCompletion(Status.STATUS_COMMITTED);
+ try {
+ execute("select * from x", new List[] {});
+ fail();
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test public void testUpdateLock() throws Exception {
+ execute("create local temporary table x (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
+ setupTransaction(Connection.TRANSACTION_SERIALIZABLE);
+ execute("insert into x (e2, e1) select e2, e1 from pm1.g1", new List[] {Arrays.asList(6)}); //$NON-NLS-1$
+ tc = null;
+ try {
+ execute("insert into x (e2, e1) select e2, e1 from pm1.g1", new List[] {Arrays.asList(6)}); //$NON-NLS-1$
+ fail();
+ } catch (Exception e) {
+
+ }
+ synch.afterCompletion(Status.STATUS_COMMITTED);
+ execute("insert into x (e2, e1) select e2, e1 from pm1.g1", new List[] {Arrays.asList(6)}); //$NON-NLS-1$
+ }
+
@Test public void testRollbackExisting1() throws Exception {
execute("create local temporary table x (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
for (int i = 0; i < 86; i++) {
@@ -160,19 +188,19 @@
tempStore = gtsi.getTempTableStore();
metadata = new TempMetadataAdapter(RealMetadataFactory.example1Cached(), tempStore.getMetadataStore());
execute("create local temporary table x (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
- for (int i = 0; i < 86; i++) {
+ for (int i = 0; i < 300; i++) {
execute("insert into x (e2, e1) select e2, e1 from pm1.g1", new List[] {Arrays.asList(6)}); //$NON-NLS-1$
}
setupTransaction(Connection.TRANSACTION_SERIALIZABLE);
- execute("select count(*) from x", new List[] {Arrays.asList(516)});
- gtsi.updateMatViewRow("X", Arrays.asList(1), true);
+ execute("select count(e1) from x", new List[] {Arrays.asList(1500)});
+ gtsi.updateMatViewRow("X", Arrays.asList(2), true);
tc=null;
//outside of the transaction we can see the row removed
- execute("select count(*) from x", new List[] {Arrays.asList(515)});
+ execute("select count(e1) from x", new List[] {Arrays.asList(1499)});
//back in the transaction we see the original state
setupTransaction(Connection.TRANSACTION_SERIALIZABLE);
- execute("select count(*) from x", new List[] {Arrays.asList(516)});
+ execute("select count(e1) from x", new List[] {Arrays.asList(1500)});
synch.afterCompletion(Status.STATUS_COMMITTED);
}
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestTempTables.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestTempTables.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/processor/TestTextTable.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestTextTable.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestTextTable.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestTextTable.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestTextTable.java:3188-3450,3452-3506
Modified: branches/as7/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -33,9 +33,8 @@
import org.junit.Test;
import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.BufferManagerFactory;
import org.teiid.common.buffer.TupleBuffer;
-import org.teiid.common.buffer.impl.BufferManagerImpl;
-import org.teiid.common.buffer.impl.MemoryStorageManager;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidException;
import org.teiid.core.types.DataTypeManager;
@@ -461,16 +460,8 @@
TestProcessor.examineResults((List[])expected.toArray(new List[expected.size()]), bufferMgr, id);
}
- private BufferManager createCustomBufferMgr(int batchSize) throws TeiidComponentException {
- BufferManagerImpl bufferMgr = new BufferManagerImpl();
- bufferMgr.setConnectorBatchSize(batchSize);
- bufferMgr.setProcessorBatchSize(batchSize);
- bufferMgr.initialize();
-
- // Add unmanaged memory storage manager
- bufferMgr.setStorageManager(new MemoryStorageManager());
-
- return bufferMgr;
+ private BufferManager createCustomBufferMgr(int batchSize) {
+ return BufferManagerFactory.getTestBufferManager(200000, batchSize);
}
public void helpTestVirtualDepJoin(boolean pushCriteria) throws Exception {
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java:3188-3450,3452-3506
Property changes on: branches/as7/engine/src/test/java/org/teiid/query/processor/TestWithClauseProcessing.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestWithClauseProcessing.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestWithClauseProcessing.java:3188-3450
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestWithClauseProcessing.java:3149-3217
/trunk/engine/src/test/java/org/teiid/query/processor/TestWithClauseProcessing.java:3188-3450,3452-3506
Modified: branches/as7/engine/src/test/java/org/teiid/query/processor/relational/TestJoinNode.java
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/query/processor/relational/TestJoinNode.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/test/java/org/teiid/query/processor/relational/TestJoinNode.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -33,9 +33,9 @@
import org.junit.Before;
import org.junit.Test;
import org.teiid.common.buffer.BlockedException;
-import org.teiid.common.buffer.BufferManager;
import org.teiid.common.buffer.BufferManagerFactory;
import org.teiid.common.buffer.TupleBatch;
+import org.teiid.common.buffer.impl.BufferManagerImpl;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.types.DataTypeManager;
@@ -232,7 +232,8 @@
}
public void helpTestJoinDirect(List[] expectedResults, int batchSize, int processingBytes) throws TeiidComponentException, TeiidProcessingException {
- BufferManager mgr = BufferManagerFactory.getTestBufferManager(processingBytes, batchSize);
+ BufferManagerImpl mgr = BufferManagerFactory.getTestBufferManager(processingBytes, batchSize);
+ mgr.setTargetBytesPerRow(100);
CommandContext context = new CommandContext("pid", "test", null, null, 1); //$NON-NLS-1$ //$NON-NLS-2$
join.addChild(leftNode);
Modified: branches/as7/engine/src/test/java/org/teiid/query/processor/relational/TestProjectIntoNode.java
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/query/processor/relational/TestProjectIntoNode.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/test/java/org/teiid/query/processor/relational/TestProjectIntoNode.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -72,10 +72,9 @@
ElementSymbol elementSymbol_2 = new ElementSymbol("myGroup.myElement2"); //$NON-NLS-1$
elementSymbol_1.setType(Integer.class);
elementSymbol_2.setType(String.class);
- ArrayList elements = new ArrayList();
- elements.add(elementSymbol_1);
- elements.add(elementSymbol_2);
+ List<ElementSymbol> elements = Arrays.asList(elementSymbol_1, elementSymbol_2);
node.setIntoElements(elements);
+ child.setElements(elements);
node.setMode(mode);
node.setModelName("myModel"); //$NON-NLS-1$
Modified: branches/as7/engine/src/test/java/org/teiid/query/sql/symbol/TestElementSymbol.java
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/query/sql/symbol/TestElementSymbol.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/engine/src/test/java/org/teiid/query/sql/symbol/TestElementSymbol.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -127,22 +127,22 @@
@Test public void testEquals5() {
ElementSymbol es = sampleElement1();
- helpEquals(es, (ElementSymbol)es.clone(), true);
+ helpEquals(es, es.clone(), true);
}
@Test public void testEquals6() {
ElementSymbol es = sampleElement2();
- helpEquals(es, (ElementSymbol)es.clone(), true);
+ helpEquals(es, es.clone(), true);
}
@Test public void testEquals7() {
ElementSymbol es = sampleElement3();
- helpEquals(es, (ElementSymbol)es.clone(), true);
+ helpEquals(es, es.clone(), true);
}
@Test public void testEquals8() {
ElementSymbol es = sampleElement4();
- helpEquals(es, (ElementSymbol)es.clone(), true);
+ helpEquals(es, es.clone(), true);
}
// Compare fully-qualified to short versions
@@ -190,7 +190,7 @@
@Test public void testCloneEquivalence(){
ElementSymbol s1 = sampleElement1();
- ElementSymbol s2 = (ElementSymbol)s1.clone();
+ ElementSymbol s2 = s1.clone();
int equals = 0;
UnitTestUtil.helpTestEquivalence(equals, s1, s2);
}
@@ -225,31 +225,31 @@
@Test public void testClone1() {
ElementSymbol e1 = sampleElement1();
- ElementSymbol copy = (ElementSymbol) e1.clone();
+ ElementSymbol copy = e1.clone();
helpEquals(e1, copy, true);
}
@Test public void testClone2() {
ElementSymbol e1 = sampleElement2();
- ElementSymbol copy = (ElementSymbol) e1.clone();
+ ElementSymbol copy = e1.clone();
helpEquals(e1, copy, true);
}
@Test public void testClone3() {
ElementSymbol e1 = sampleElement3();
- ElementSymbol copy = (ElementSymbol) e1.clone();
+ ElementSymbol copy = e1.clone();
helpEquals(e1, copy, true);
}
@Test public void testClone4() {
ElementSymbol e1 = sampleElement4();
- ElementSymbol copy = (ElementSymbol) e1.clone();
+ ElementSymbol copy = e1.clone();
helpEquals(e1, copy, true);
}
@Test public void testClone5() {
ElementSymbol e1 = sampleElement1();
- ElementSymbol copy = (ElementSymbol) e1.clone();
+ ElementSymbol copy = e1.clone();
helpEquals(e1, copy, true);
// Change original, clone shouldn't change
Property changes on: branches/as7/engine/src/test/resources/text/cdm_dos_win.txt
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/resources/text/cdm_dos_win.txt:3149-3164,3172-3217
/trunk/engine/src/test/resources/text/cdm_dos_win.txt:3188-3450
+ /branches/7.4.x/engine/src/test/resources/text/cdm_dos_win.txt:3149-3164,3172-3217
/trunk/engine/src/test/resources/text/cdm_dos_win.txt:3188-3450,3452-3506
Modified: branches/as7/jboss-integration/pom.xml
===================================================================
--- branches/as7/jboss-integration/pom.xml 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/jboss-integration/pom.xml 2011-09-29 16:46:38 UTC (rev 3507)
@@ -203,7 +203,12 @@
<scope>test</scope>
</dependency>
-->
-
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-common-core</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Modified: branches/as7/metadata/src/main/java/org/teiid/internal/core/index/BlocksIndexInput.java
===================================================================
--- branches/as7/metadata/src/main/java/org/teiid/internal/core/index/BlocksIndexInput.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/metadata/src/main/java/org/teiid/internal/core/index/BlocksIndexInput.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -60,9 +60,12 @@
//System.out.println(" Closing Index File: " + this.indexFile.getName());
summary= null;
setOpen(false);
- if (raf != null)
+ if (raf != null) {
raf.close();
- vraf.close();
+ }
+ if (vraf != null) {
+ vraf.close();
+ }
}
}
Modified: branches/as7/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java
===================================================================
--- branches/as7/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -29,7 +29,9 @@
import org.teiid.common.buffer.BufferManager;
import org.teiid.common.buffer.impl.BufferManagerImpl;
import org.teiid.common.buffer.impl.FileStorageManager;
+import org.teiid.common.buffer.impl.FileStoreCache;
import org.teiid.common.buffer.impl.MemoryStorageManager;
+import org.teiid.common.buffer.impl.SplittableStorageManager;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.util.FileUtils;
@@ -56,10 +58,11 @@
private int processorBatchSize = BufferManager.DEFAULT_PROCESSOR_BATCH_SIZE;
private int connectorBatchSize = BufferManager.DEFAULT_CONNECTOR_BATCH_SIZE;
private int maxOpenFiles = FileStorageManager.DEFAULT_MAX_OPEN_FILES;
- private long maxFileSize = FileStorageManager.DEFAULT_MAX_FILESIZE; // 2GB
+ private long maxFileSize = SplittableStorageManager.DEFAULT_MAX_FILESIZE; // 2GB
private int maxProcessingKb = BufferManager.DEFAULT_MAX_PROCESSING_KB;
private int maxReserveKb = BufferManager.DEFAULT_RESERVE_BUFFER_KB;
- private long maxBufferSpace = FileStorageManager.DEFAULT_MAX_BUFFERSPACE;
+ private long maxBufferSpace = FileStorageManager.DEFAULT_MAX_BUFFERSPACE>>20;
+ private boolean inlineLobs = true;
private FileStorageManager fsm;
/**
@@ -94,13 +97,17 @@
// Get the properties for FileStorageManager and create.
fsm = new FileStorageManager();
fsm.setStorageDirectory(bufferDir.getCanonicalPath());
- fsm.setMaxFileSize(maxFileSize);
fsm.setMaxOpenFiles(maxOpenFiles);
fsm.setMaxBufferSpace(maxBufferSpace*MB);
- fsm.initialize();
- this.bufferMgr.setStorageManager(fsm);
+ SplittableStorageManager ssm = new SplittableStorageManager(fsm);
+ ssm.setMaxFileSize(maxFileSize);
+ FileStoreCache fsc = new FileStoreCache();
+ fsc.setStorageManager(ssm);
+ fsc.setMaxBufferSpace(maxBufferSpace*MB);
+ fsc.initialize();
+ this.bufferMgr.setCache(fsc);
} else {
- this.bufferMgr.setStorageManager(new MemoryStorageManager());
+ this.bufferMgr.setCache(new MemoryStorageManager());
}
} catch(TeiidComponentException e) {
@@ -121,7 +128,7 @@
}
}
- public BufferManager getBufferManager() {
+ public BufferManagerImpl getBufferManager() {
return this.bufferMgr;
}
@@ -139,6 +146,10 @@
public void setConnectorBatchSize(int size) {
this.connectorBatchSize = size;
}
+
+ public void setInlineLobs(boolean inlineLobs) {
+ this.inlineLobs = inlineLobs;
+ }
public File getBufferDirectory() {
return bufferDir;
@@ -147,6 +158,10 @@
public boolean isUseDisk() {
return this.useDisk;
}
+
+ public boolean isInlineLobs() {
+ return inlineLobs;
+ }
public int getProcessorBatchSize() {
return this.processorBatchSize;
Modified: branches/as7/runtime/src/test/java/org/teiid/dqp/service/buffer/TestLocalBufferService.java
===================================================================
--- branches/as7/runtime/src/test/java/org/teiid/dqp/service/buffer/TestLocalBufferService.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/runtime/src/test/java/org/teiid/dqp/service/buffer/TestLocalBufferService.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -37,6 +37,8 @@
import org.teiid.common.buffer.BufferManager.TupleSourceType;
import org.teiid.common.buffer.impl.BufferManagerImpl;
import org.teiid.common.buffer.impl.FileStorageManager;
+import org.teiid.common.buffer.impl.FileStoreCache;
+import org.teiid.common.buffer.impl.SplittableStorageManager;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.types.DataTypeManager.DefaultDataTypes;
import org.teiid.core.util.UnitTestUtil;
@@ -60,8 +62,9 @@
assertTrue("does not end with one", svc.getBufferDirectory().getParent().endsWith("1")); //$NON-NLS-1$ //$NON-NLS-2$
assertTrue(svc.isUseDisk());
- BufferManagerImpl mgr = (BufferManagerImpl) svc.getBufferManager();
- assertTrue(((FileStorageManager)mgr.getStorageManager()).getDirectory().endsWith(svc.getBufferDirectory().getName()));
+ BufferManagerImpl mgr = svc.getBufferManager();
+ SplittableStorageManager ssm = (SplittableStorageManager)((FileStoreCache)mgr.getCache()).getStorageManager();
+ assertTrue(((FileStorageManager)ssm.getStorageManager()).getDirectory().endsWith(svc.getBufferDirectory().getName()));
}
@Test public void testCheckMemPropertyGotSet2() throws Exception {
@@ -99,7 +102,8 @@
svc.start();
BufferManager mgr = svc.getBufferManager();
- assertEquals(13141, mgr.getSchemaSize(schema));
+ assertEquals(6570, mgr.getSchemaSize(schema));
+ assertEquals(256, mgr.getProcessorBatchSize(schema));
}
@Test
Modified: branches/as7/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewReplication.java
===================================================================
--- branches/as7/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewReplication.java 2011-09-29 01:08:46 UTC (rev 3506)
+++ branches/as7/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewReplication.java 2011-09-29 16:46:38 UTC (rev 3507)
@@ -30,9 +30,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
-import java.util.logging.Handler;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import org.jboss.as.clustering.jgroups.ChannelFactory;
import org.jgroups.Channel;
@@ -60,16 +57,7 @@
@Test public void testReplication() throws Exception {
if (DEBUG) {
- Logger logger = Logger.getLogger("org.teiid");
- logger.setLevel(Level.FINEST);
- for (Handler h : logger.getHandlers()) {
- h.setLevel(Level.FINEST);
- }
- /*org.apache.log4j.Logger l = LogManager.getLogger("org.jgroups");
- l.setLevel(org.apache.log4j.Level.TRACE);
- ConsoleAppender ca = new ConsoleAppender(new PatternLayout());
- ca.setName("x");
- l.addAppender(ca);*/
+ UnitTestUtil.enableTraceLogging("org.teiid");
}
FakeServer server1 = createServer();
Property changes on: branches/as7/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java:3149-3217,3281-3325
/trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java:3188-3450
+ /branches/7.4.x/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java:3149-3217,3281-3325
/trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java:3188-3450,3452-3506
Property changes on: branches/as7/test-integration/common/src/test/resources/TestODBCSocketTransport/testPk.expected
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/test-integration/common/src/test/resources/TestODBCSocketTransport/testPk.expected:3281-3325
/trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testPk.expected:3188-3450
+ /branches/7.4.x/test-integration/common/src/test/resources/TestODBCSocketTransport/testPk.expected:3281-3325
/trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testPk.expected:3188-3450,3452-3506
Property changes on: branches/as7/test-integration/common/src/test/resources/TestODBCSocketTransport/testPkPrepared.expected
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/test-integration/common/src/test/resources/TestODBCSocketTransport/testPkPrepared.expected:3281-3325
/trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testPkPrepared.expected:3188-3450
+ /branches/7.4.x/test-integration/common/src/test/resources/TestODBCSocketTransport/testPkPrepared.expected:3281-3325
/trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testPkPrepared.expected:3188-3450,3452-3506
Property changes on: branches/as7/test-integration/common/src/test/resources/TestSystemVirtualModel/testProcedureParams.expected
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/test-integration/common/src/test/resources/TestSystemVirtualModel/testProcedureParams.expected:3220-3275
/trunk/test-integration/common/src/test/resources/TestSystemVirtualModel/testProcedureParams.expected:3188-3450
+ /branches/7.4.x/test-integration/common/src/test/resources/TestSystemVirtualModel/testProcedureParams.expected:3220-3275
/trunk/test-integration/common/src/test/resources/TestSystemVirtualModel/testProcedureParams.expected:3188-3450,3452-3506
Property changes on: branches/as7/test-integration/common/src/test/resources/TestSystemVirtualModel/testProcedures.expected
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/test-integration/common/src/test/resources/TestSystemVirtualModel/testProcedures.expected:3220-3275
/trunk/test-integration/common/src/test/resources/TestSystemVirtualModel/testProcedures.expected:3188-3450
+ /branches/7.4.x/test-integration/common/src/test/resources/TestSystemVirtualModel/testProcedures.expected:3220-3275
/trunk/test-integration/common/src/test/resources/TestSystemVirtualModel/testProcedures.expected:3188-3450,3452-3506
[View Less]
13 years, 6 months
teiid SVN: r3506 - in branches/as7: engine/src/test/java/org/teiid/dqp/internal/process and 6 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2011-09-28 21:08:46 -0400 (Wed, 28 Sep 2011)
New Revision: 3506
Modified:
branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java
branches/as7/engine/src/test/java/org/teiid/dqp/internal/process/TestCachedResults.java
branches/as7/metadata/pom.xml
branches/as7/runtime/src/main/java/org/teiid/deployers/PgCatalogMetadataStore.java
branches/as7/runtime/src/main/java/org/teiid/deployers/TranslatorUtil.java
branches/as7/runtime/src/…
[View More]main/java/org/teiid/services/TeiidLoginContext.java
branches/as7/runtime/src/test/java/org/teiid/services/TestMembershipServiceImpl.java
branches/as7/test-integration/common/
branches/as7/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java
Log:
TEIID-1720: fix tests
Modified: branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java 2011-09-28 15:25:16 UTC (rev 3505)
+++ branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java 2011-09-29 01:08:46 UTC (rev 3506)
@@ -118,7 +118,7 @@
return false;
}
}
- return true;
+ return (this.results != null);
}
@Override
Modified: branches/as7/engine/src/test/java/org/teiid/dqp/internal/process/TestCachedResults.java
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/dqp/internal/process/TestCachedResults.java 2011-09-28 15:25:16 UTC (rev 3505)
+++ branches/as7/engine/src/test/java/org/teiid/dqp/internal/process/TestCachedResults.java 2011-09-29 01:08:46 UTC (rev 3506)
@@ -21,7 +21,10 @@
*/
package org.teiid.dqp.internal.process;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.List;
@@ -30,11 +33,12 @@
import org.teiid.cache.Cache;
import org.teiid.cache.DefaultCache;
import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.common.buffer.TestTupleBuffer.FakeBatchManager;
import org.teiid.common.buffer.TupleBuffer;
-import org.teiid.common.buffer.TestTupleBuffer.FakeBatchManager;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.UnitTestUtil;
-import org.teiid.dqp.service.FakeBufferService;
+import org.teiid.dqp.service.BufferService;
import org.teiid.metadata.Table;
import org.teiid.query.processor.FakeProcessorPlan;
import org.teiid.query.processor.ProcessorPlan;
@@ -48,7 +52,12 @@
@Test
public void testCaching() throws Exception {
- FakeBufferService fbs = new FakeBufferService();
+ BufferService fbs = new BufferService() {
+ @Override
+ public BufferManager getBufferManager() {
+ return BufferManagerFactory.getStandaloneBufferManager();
+ }
+ };
ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$
x.setType(DataTypeManager.DefaultDataClasses.INTEGER);
@@ -88,12 +97,18 @@
results.prepare(cache, bm);
+ //simulate distribute
+ TupleBuffer distributedTb = bm.getTupleBuffer(results.getId());
+
CachedResults cachedResults = UnitTestUtil.helpSerialize(results);
RealMetadataFactory.buildWorkContext(RealMetadataFactory.exampleBQT());
- assertTrue(cachedResults.restore(cache, bm));
+ BufferManager bm2 = fbs.getBufferManager();
+ bm2.distributeTupleBuffer(results.getId(), distributedTb);
+ assertTrue(cachedResults.restore(cache, bm2));
+
// since restored, simulate a async cache flush
cache.clear();
@@ -107,9 +122,9 @@
assertArrayEquals(tb.getBatch(9).getAllTuples(), cachedTb.getBatch(9).getAllTuples());
assertTrue(ts - cachedResults.getAccessInfo().getCreationTime() <= 5000);
- //ensure that an incomplete load fails
- cache.remove(results.getId()+","+1); //$NON-NLS-1$
- cachedResults = UnitTestUtil.helpSerialize(results);
- assertFalse(cachedResults.restore(cache, bm));
+ //ensure that an incomplete load fails ( is this still valid use case?)
+// bm2.getTupleBuffer(results.getId()).remove();
+// cachedResults = UnitTestUtil.helpSerialize(results);
+// assertFalse(cachedResults.restore(cache, bm2));
}
}
Modified: branches/as7/metadata/pom.xml
===================================================================
--- branches/as7/metadata/pom.xml 2011-09-28 15:25:16 UTC (rev 3505)
+++ branches/as7/metadata/pom.xml 2011-09-29 01:08:46 UTC (rev 3506)
@@ -44,7 +44,7 @@
<dependency>
<groupId>org.jboss.teiid</groupId>
<artifactId>teiid-admin</artifactId>
- <scope>test</scope>
+ <scope>provided</scope>
</dependency>
<dependency>
Modified: branches/as7/runtime/src/main/java/org/teiid/deployers/PgCatalogMetadataStore.java
===================================================================
--- branches/as7/runtime/src/main/java/org/teiid/deployers/PgCatalogMetadataStore.java 2011-09-28 15:25:16 UTC (rev 3505)
+++ branches/as7/runtime/src/main/java/org/teiid/deployers/PgCatalogMetadataStore.java 2011-09-29 01:08:46 UTC (rev 3506)
@@ -520,21 +520,25 @@
private FunctionMethod addHasFunctionPrivilage() throws TranslatorException {
FunctionMethod func = addFunction("has_function_privilege"); //$NON-NLS-1$
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
- ArrayList<FunctionParameter> inParams = new ArrayList<FunctionParameter>();
- inParams.add(new FunctionParameter("oid", DataTypeManager.DefaultDataTypes.INTEGER, ""));//$NON-NLS-1$ //$NON-NLS-2$
- inParams.add(new FunctionParameter("permission", DataTypeManager.DefaultDataTypes.STRING, "")); //$NON-NLS-1$ //$NON-NLS-2$
-
- func.setInputParameters(inParams);
- func.setOutputParameter(new FunctionParameter("result", DataTypeManager.DefaultDataTypes.BOOLEAN, "")); //$NON-NLS-1$ //$NON-NLS-2$
-
- func.setInvocationClass(ReturnTrue.class.getName());
- func.setInvocationMethod("result"); //$NON-NLS-1$
- func.setPushdown(PushDown.CANNOT_PUSHDOWN);
- func.setClassloader(Module.getModuleFromCallerModuleLoader(ModuleIdentifier.create("org.jboss.teiid")).getClassLoader()); //$NON-NLS-1$
+ classLoader = Module.getModuleFromCallerModuleLoader(ModuleIdentifier.create("org.jboss.teiid")).getClassLoader(); //$NON-NLS-1$
} catch (ModuleLoadException e) {
- throw new TranslatorException(e);
+ // only in test situations
}
+
+ ArrayList<FunctionParameter> inParams = new ArrayList<FunctionParameter>();
+ inParams.add(new FunctionParameter("oid", DataTypeManager.DefaultDataTypes.INTEGER, ""));//$NON-NLS-1$ //$NON-NLS-2$
+ inParams.add(new FunctionParameter("permission", DataTypeManager.DefaultDataTypes.STRING, "")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ func.setInputParameters(inParams);
+ func.setOutputParameter(new FunctionParameter("result", DataTypeManager.DefaultDataTypes.BOOLEAN, "")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ func.setInvocationClass(ReturnTrue.class.getName());
+ func.setInvocationMethod("result"); //$NON-NLS-1$
+ func.setPushdown(PushDown.CANNOT_PUSHDOWN);
+ func.setClassloader(classLoader);
+
return func;
}
Modified: branches/as7/runtime/src/main/java/org/teiid/deployers/TranslatorUtil.java
===================================================================
--- branches/as7/runtime/src/main/java/org/teiid/deployers/TranslatorUtil.java 2011-09-28 15:25:16 UTC (rev 3505)
+++ branches/as7/runtime/src/main/java/org/teiid/deployers/TranslatorUtil.java 2011-09-29 01:08:46 UTC (rev 3506)
@@ -93,18 +93,20 @@
public static ExecutionFactory buildExecutionFactory(VDBTranslatorMetaData data) throws TeiidException {
ExecutionFactory executionFactory;
- final ModuleIdentifier moduleId;
- final Module module;
- try {
- moduleId = ModuleIdentifier.create(data.getModuleName());
- module = Module.getCallerModuleLoader().loadModule(moduleId);
- } catch (ModuleLoadException e) {
- throw new TeiidException(e, RuntimePlugin.Util.getString("failed_load_module", data.getModuleName(), data.getName())); //$NON-NLS-1$
- }
+ ClassLoader classloader = Thread.currentThread().getContextClassLoader();
+ if (data.getModuleName() != null) {
+ try {
+ final ModuleIdentifier moduleId = ModuleIdentifier.create(data.getModuleName());
+ final Module module = Module.getCallerModuleLoader().loadModule(moduleId);
+ classloader = module.getClassLoader();
+ } catch (ModuleLoadException e) {
+ throw new TeiidException(e, RuntimePlugin.Util.getString("failed_load_module", data.getModuleName(), data.getName())); //$NON-NLS-1$
+ }
+ }
try {
String executionClass = data.getPropertyValue(VDBTranslatorMetaData.EXECUTION_FACTORY_CLASS);
- Object o = ReflectionHelper.create(executionClass, null, module.getClassLoader());
+ Object o = ReflectionHelper.create(executionClass, null, classloader);
if(!(o instanceof ExecutionFactory)) {
throw new TeiidException(RuntimePlugin.Util.getString("invalid_class", executionClass));//$NON-NLS-1$
}
Modified: branches/as7/runtime/src/main/java/org/teiid/services/TeiidLoginContext.java
===================================================================
--- branches/as7/runtime/src/main/java/org/teiid/services/TeiidLoginContext.java 2011-09-28 15:25:16 UTC (rev 3505)
+++ branches/as7/runtime/src/main/java/org/teiid/services/TeiidLoginContext.java 2011-09-29 01:08:46 UTC (rev 3506)
@@ -96,11 +96,11 @@
if (authManager != null) {
Principal userPrincipal = new SimplePrincipal(username);
Subject subject = new Subject();
- boolean isValid = authManager.isValid(userPrincipal, new String(credential.getCredentialsAsCharArray()), subject);
+ boolean isValid = authManager.isValid(userPrincipal, credential==null?null:new String(credential.getCredentialsAsCharArray()), subject);
if (isValid) {
this.userName = baseUsername+AT+domain;
this.securitydomain = domain;
- this.securityContext = this.securityHelper.createSecurityContext(this.securitydomain, userPrincipal, new String(credential.getCredentialsAsCharArray()), subject);
+ this.securityContext = this.securityHelper.createSecurityContext(this.securitydomain, userPrincipal, credential==null?null:new String(credential.getCredentialsAsCharArray()), subject);
LogManager.logDetail(LogConstants.CTX_SECURITY, new Object[] {"Logon successful for \"", username, "\""}); //$NON-NLS-1$ //$NON-NLS-2$
return;
}
Modified: branches/as7/runtime/src/test/java/org/teiid/services/TestMembershipServiceImpl.java
===================================================================
--- branches/as7/runtime/src/test/java/org/teiid/services/TestMembershipServiceImpl.java 2011-09-28 15:25:16 UTC (rev 3505)
+++ branches/as7/runtime/src/test/java/org/teiid/services/TestMembershipServiceImpl.java 2011-09-29 01:08:46 UTC (rev 3506)
@@ -73,15 +73,31 @@
domains.add("testFile"); //$NON-NLS-1$
Map<String, SecurityDomainContext> securityDomainMap = new HashMap<String, SecurityDomainContext>();
SecurityDomainContext securityContext = Mockito.mock(SecurityDomainContext.class);
- AuthenticationManager authManager = Mockito.mock(AuthenticationManager.class);
- Mockito.stub(authManager.isValid(new SimplePrincipal("user1"), credentials, new Subject())).toReturn(true);
+ AuthenticationManager authManager = new AuthenticationManager() {
+ public String getSecurityDomain() {
+ return null;
+ }
+ public boolean isValid(Principal principal, Object credential, Subject activeSubject) {
+ return true;
+ }
+ public boolean isValid(Principal principal, Object credential) {
+ return true;
+ }
+
+ @Override
+ public Principal getTargetPrincipal(Principal anotherDomainPrincipal, Map<String, Object> contextMap) {
+ return null;
+ }
+ @Override
+ public Subject getActiveSubject() {
+ return null;
+ }
+ };
+
Mockito.stub(securityContext.getAuthenticationManager()).toReturn(authManager);
securityDomainMap.put("testFile", securityContext); //$NON-NLS-1$
ms.authenticateUser("user1", credentials, null, domains,securityDomainMap, false); //$NON-NLS-1$ //$NON-NLS-2$
-
- Mockito.verify(authManager).isValid(new SimplePrincipal("user1"), credentials, new Subject());
-
assertEquals("user1@testFile", ms.getUserName()); //$NON-NLS-1$
}
Property changes on: branches/as7/test-integration/common
___________________________________________________________________
Modified: svn:ignore
- target
.settings
.classpath
.project
derby.log
+ target
.settings
.classpath
.project
derby.log
transaction.log
Modified: branches/as7/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java
===================================================================
--- branches/as7/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java 2011-09-28 15:25:16 UTC (rev 3505)
+++ branches/as7/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java 2011-09-29 01:08:46 UTC (rev 3506)
@@ -44,6 +44,7 @@
import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository;
import org.teiid.dqp.internal.datamgr.FakeTransactionService;
import org.teiid.dqp.internal.process.*;
+import org.teiid.dqp.service.BufferService;
import org.teiid.dqp.service.FakeBufferService;
import org.teiid.metadata.FunctionMethod;
import org.teiid.metadata.MetadataRepository;
@@ -149,17 +150,22 @@
this.repo.start();
this.sessionService.setVDBRepository(repo);
- this.dqp.setBufferService(new FakeBufferService());
+ BufferService fbs = new FakeBufferService();
+ this.dqp.setBufferService(fbs);
DefaultCacheFactory dcf = new DefaultCacheFactory() {
@Override
public boolean isReplicated() {
return true; //pretend to be replicated for matview tests
}
};
+
+ SessionAwareCache rs = new SessionAwareCache<CachedResults>(dcf, SessionAwareCache.Type.RESULTSET, new CacheConfiguration(Policy.LRU, 60, 250, "resultsetcache"));
+ rs.setBufferManager(fbs.getBufferManager());
+ this.dqp.setResultsetCache(rs);
+ SessionAwareCache ppc = new SessionAwareCache<PreparedPlan>(dcf, SessionAwareCache.Type.PREPAREDPLAN, new CacheConfiguration());
+ ppc.setBufferManager(fbs.getBufferManager());
+ this.dqp.setPreparedPlanCache(ppc);
- this.dqp.setResultsetCache(new SessionAwareCache<CachedResults>(dcf, SessionAwareCache.Type.RESULTSET, new CacheConfiguration(Policy.LRU, 60, 250, "resultsetcache")));
- this.dqp.setPreparedPlanCache(new SessionAwareCache<PreparedPlan>(dcf, SessionAwareCache.Type.PREPAREDPLAN, new CacheConfiguration()));
-
this.dqp.setTransactionService(new FakeTransactionService());
cmr = Mockito.mock(ConnectorManagerRepository.class);
[View Less]
13 years, 6 months
teiid SVN: r3505 - in branches/as7: admin/src/main/java/org/teiid/adminapi/impl and 10 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2011-09-28 11:25:16 -0400 (Wed, 28 Sep 2011)
New Revision: 3505
Added:
branches/as7/admin/src/test/resources/parser-test-vdb.xml
branches/as7/jboss-integration/src/test/java/org/teiid/jboss/TestTeiidAdminOperations.java
branches/as7/jboss-integration/src/test/resources/teiid-model-json.txt
Modified:
branches/as7/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java
branches/as7/build/kits/jboss-as7/standalone/configuration/standalone-teiid.xml
…
[View More] branches/as7/engine/src/main/java/org/teiid/query/function/FunctionTree.java
branches/as7/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
branches/as7/jboss-integration/pom.xml
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/Configuration.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/Element.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/ObjectSerializer.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/QueryEngineAdd.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/QueryEngineOperationHandler.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidBootServicesAdd.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidExtension.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidSubsystemDescribe.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidSubsystemParser.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TranslatorAdd.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/VDBParserDeployer.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
branches/as7/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties
branches/as7/jboss-integration/src/main/resources/schema/jboss-teiid.xsd
branches/as7/jboss-integration/src/test/java/org/teiid/jboss/TestTeiidConfiguration.java
branches/as7/jboss-integration/src/test/resources/teiid-model-config.txt
branches/as7/jboss-integration/src/test/resources/teiid-sample-config.xml
branches/as7/pom.xml
Log:
TEIID-1720: Lot of re-arrgangement of the configuration to have a flat model but xml for the persistence form.
Modified: branches/as7/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java
===================================================================
--- branches/as7/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java 2011-09-28 15:25:16 UTC (rev 3505)
@@ -21,6 +21,7 @@
*/
package org.teiid.adminapi.impl;
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.*;
@@ -305,9 +306,10 @@
}
}
- public static void marshell(VDBMetaData vdb, OutputStream out) throws XMLStreamException {
+ public static void marshell(VDBMetaData vdb, OutputStream out) throws XMLStreamException, IOException {
XMLStreamWriter writer = XMLOutputFactory.newFactory().createXMLStreamWriter(out);
+ writer.writeStartDocument();
writer.writeStartElement(Element.VDB.getLocalName());
writer.writeAttribute(Element.NAME.getLocalName(), vdb.getName());
writer.writeAttribute(Element.VERSION.getLocalName(), String.valueOf(vdb.getVersion()));
@@ -337,6 +339,9 @@
// designer only
writer.writeEndElement();
+ writer.writeEndDocument();
+ writer.close();
+ out.close();
}
private static void writeDataPolicy(XMLStreamWriter writer, DataPolicy dp) throws XMLStreamException {
Added: branches/as7/admin/src/test/resources/parser-test-vdb.xml
===================================================================
--- branches/as7/admin/src/test/resources/parser-test-vdb.xml (rev 0)
+++ branches/as7/admin/src/test/resources/parser-test-vdb.xml 2011-09-28 15:25:16 UTC (rev 3505)
@@ -0,0 +1,34 @@
+<vdb name="myVDB" version="1">
+ <description>vdb description</description>
+ <property name="vdb-property2" value="vdb-value2"></property>
+ <property name="vdb-property" value="vdb-value"></property>
+ <model name="model-one" type="PHYSICAL" visible="false">
+ <description>model description</description>
+ <property name="model-prop" value="model-value-override"></property>
+ <source name="s1" translator-name="translator" connection-jndi-name="java:mybinding"></source>
+ <validation-error severity="ERROR">There is an error in VDB</validation-error>
+ </model>
+ <model name="model-two" type="VIRTUAL" visible="true">
+ <property name="model-prop" value="model-value"></property>
+ <source name="s1" translator-name="translator" connection-jndi-name="java:binding-one"></source>
+ <source name="s2" translator-name="translator" connection-jndi-name="java:binding-two"></source>
+ </model>
+ <translator name="oracleOverride" type="oracle" description="hello world">
+ <property name="my-property" value="my-value"></property>
+ </translator>
+ <data-role name="roleOne" any-authenticated="false" allow-create-temporary-tables="true">
+ <description>roleOne described</description>
+ <permission>
+ <resource-name>myTable.T1</resource-name>
+ <allow-read>true</allow-read>
+ </permission>
+ <permission>
+ <resource-name>myTable.T2</resource-name>
+ <allow-read>false</allow-read>
+ <allow-delete>true</allow-delete>
+ </permission>
+ <mapped-role-name>ROLE1</mapped-role-name>
+ <mapped-role-name>ROLE2</mapped-role-name>
+ </data-role>
+</vdb>
+
Property changes on: branches/as7/admin/src/test/resources/parser-test-vdb.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: branches/as7/build/kits/jboss-as7/standalone/configuration/standalone-teiid.xml
===================================================================
--- branches/as7/build/kits/jboss-as7/standalone/configuration/standalone-teiid.xml 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/build/kits/jboss-as7/standalone/configuration/standalone-teiid.xml 2011-09-28 15:25:16 UTC (rev 3505)
@@ -106,19 +106,32 @@
<password>sa</password>
</security>
</datasource>
- <datasource jndi-name="java:/Oracle11_PushDS" pool-name="OracleDS" enabled="true" jta="true" use-java-context="true" use-ccm="true">
- <connection-url>jdbc:oracle:thin:@englxdbs11.mw.lab.eng.bos.redhat.com:1521:orcl</connection-url>
- <driver>oracle</driver>
+ <datasource jndi-name="java:/postgres-ds" pool-name="PostgreDS">
+ <connection-url>jdbc:postgresql://127.0.0.1:5432/txns</connection-url>
+ <driver>postgresql-8.3-603.jdbc3.jar</driver>
<pool>
<prefill>false</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
- <user-name>bqt2_ro</user-name>
+ <user-name>rareddy</user-name>
<password>mm</password>
</security>
- </datasource>
+ </datasource>
+ <datasource jndi-name="java:/mysql-ds" pool-name="mysqlDS">
+ <connection-url>jdbc:mysql://localhost:3306/txns</connection-url>
+ <driver>mysql-connector-java-5.1.5.jar</driver>
+ <pool>
+ <prefill>false</prefill>
+ <use-strict-min>false</use-strict-min>
+ <flush-strategy>FailingConnectionOnly</flush-strategy>
+ </pool>
+ <security>
+ <user-name>rareddy</user-name>
+ <password>mm</password>
+ </security>
+ </datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
Modified: branches/as7/engine/src/main/java/org/teiid/query/function/FunctionTree.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/query/function/FunctionTree.java 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/engine/src/main/java/org/teiid/query/function/FunctionTree.java 2011-09-28 15:25:16 UTC (rev 3505)
@@ -295,7 +295,7 @@
// Defect 20007 - Ignore the invocation method if pushdown is not required.
if (validateClass && (method.getPushdown() == PushDown.CAN_PUSHDOWN || method.getPushdown() == PushDown.CANNOT_PUSHDOWN)) {
try {
- Class<?> methodClass = source.getInvocationClass(method.getInvocationClass(), method.getClassLoader());
+ Class<?> methodClass = source.getInvocationClass(method.getInvocationClass(), method.getClassLoader()==null?Thread.currentThread().getContextClassLoader():method.getClassLoader());
ReflectionHelper helper = new ReflectionHelper(methodClass);
try {
invocationMethod = helper.findBestMethodWithSignature(method.getInvocationMethod(), inputTypes);
Modified: branches/as7/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
===================================================================
--- branches/as7/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java 2011-09-28 15:25:16 UTC (rev 3505)
@@ -108,15 +108,15 @@
ConnectorManagerRepository repo = Mockito.mock(ConnectorManagerRepository.class);
context.getVDB().addAttchment(ConnectorManagerRepository.class, repo);
Mockito.stub(repo.getConnectorManager(Mockito.anyString())).toReturn(agds);
-
- core = new DQPCore();
- core.setBufferService(new BufferService() {
+ BufferService bs = new BufferService() {
@Override
public BufferManager getBufferManager() {
return BufferManagerFactory.createBufferManager();
}
- });
+ };
+ core = new DQPCore();
+ core.setBufferService(bs);
core.setResultsetCache(new SessionAwareCache<CachedResults>(new DefaultCacheFactory(), SessionAwareCache.Type.RESULTSET, new CacheConfiguration()));
core.setPreparedPlanCache(new SessionAwareCache<PreparedPlan>(new DefaultCacheFactory(), SessionAwareCache.Type.PREPAREDPLAN, new CacheConfiguration()));
core.setTransactionService(new FakeTransactionService());
@@ -126,7 +126,7 @@
config.setUserRequestSourceConcurrency(2);
core.start(config);
core.getPrepPlanCache().setModTime(1);
- core.getRsCache().setModTime(1);
+ core.getRsCache().setBufferManager(bs.getBufferManager());
}
@After public void tearDown() throws Exception {
Modified: branches/as7/jboss-integration/pom.xml
===================================================================
--- branches/as7/jboss-integration/pom.xml 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/jboss-integration/pom.xml 2011-09-28 15:25:16 UTC (rev 3505)
@@ -96,6 +96,12 @@
<artifactId>jboss-as-server</artifactId>
<scope>provided</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.jboss.as</groupId>
+ <artifactId>jboss-as-subsystem-test</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>log4j</groupId>
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/Configuration.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/Configuration.java 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/Configuration.java 2011-09-28 15:25:16 UTC (rev 3505)
@@ -82,7 +82,6 @@
public static final String IN_BUFFER_SIZE = "input-buffer-size";//$NON-NLS-1$
public static final String OUT_BUFFER_SIZE = "output-buffer-size";//$NON-NLS-1$
public static final String SOCKET_BINDING = "socket-binding";//$NON-NLS-1$
- public static final String SOCKET_ENABLED = "enabled";//$NON-NLS-1$
public static final String SSL_MODE = "mode";//$NON-NLS-1$
public static final String KEY_STORE_FILE = "keystore-name";//$NON-NLS-1$
public static final String KEY_STORE_PASSWD = "keystore-password";//$NON-NLS-1$
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/Element.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/Element.java 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/Element.java 2011-09-28 15:25:16 UTC (rev 3505)
@@ -22,18 +22,24 @@
package org.teiid.jboss;
+import static org.teiid.jboss.Configuration.*;
+
import java.util.HashMap;
import java.util.Map;
-import static org.teiid.jboss.Configuration.*;
enum Element {
// must be first
UNKNOWN(null),
// VM wide elements
- QUERY_ENGINE_ELEMENT(QUERY_ENGINE),
ASYNC_THREAD_GROUP_ELEMENT(ASYNC_THREAD_GROUP),
+ ALLOW_ENV_FUNCTION_ELEMENT(ALLOW_ENV_FUNCTION),
+ POLICY_DECIDER_MODULE_ELEMENT(POLICY_DECIDER_MODULE),
+ BUFFER_SERVICE_ELEMENT(BUFFER_SERVICE),
+ PREPAREDPLAN_CACHE_ELEMENT(PREPAREDPLAN_CACHE),
+ RESULTSET_CACHE_ELEMENT(RESULTSET_CACHE),
OBJECT_REPLICATOR_ELEMENT(OBJECT_REPLICATOR),
+ QUERY_ENGINE_ELEMENT(QUERY_ENGINE),
// Query-ENGINE
ENGINE_NAME_ATTRIBUTE(ENGINE_NAME),
@@ -44,7 +50,6 @@
MAX_ROWS_FETCH_SIZE_ELEMENT(MAX_ROWS_FETCH_SIZE),
LOB_CHUNK_SIZE_IN_KB_ELEMENT(LOB_CHUNK_SIZE_IN_KB),
AUTHORIZATION_VALIDATOR_MODULE_ELEMENT(AUTHORIZATION_VALIDATOR_MODULE),
- POLICY_DECIDER_MODULE_ELEMENT(POLICY_DECIDER_MODULE),
QUERY_THRESHOLD_IN_SECS_ELEMENT(QUERY_THRESHOLD_IN_SECS),
MAX_SOURCE_ROWS_ELEMENT(MAX_SOURCE_ROWS),
EXCEPTION_ON_MAX_SOURCE_ROWS_ELEMENT(EXCEPTION_ON_MAX_SOURCE_ROWS),
@@ -52,65 +57,82 @@
DETECTING_CHANGE_EVENTS_ELEMENT(DETECTING_CHANGE_EVENTS),
MAX_SESSIONS_ALLOWED_ELEMENT(MAX_SESSIONS_ALLOWED),
SESSION_EXPIRATION_TIME_LIMIT_ELEMENT(SESSION_EXPIRATION_TIME_LIMIT),
- ALLOW_ENV_FUNCTION_ELEMENT(ALLOW_ENV_FUNCTION),
SECURITY_DOMAIN_ELEMENT(SECURITY_DOMAIN),
-
- //children
- BUFFER_SERVICE_ELEMENT(BUFFER_SERVICE),
- PREPAREDPLAN_CACHE_ELEMENT(PREPAREDPLAN_CACHE),
- RESULTSET_CACHE_ELEMENT(RESULTSET_CACHE),
JDBC_ELEMENT(JDBC),
ODBC_ELEMENT(ODBC),
// buffer manager
- USE_DISK_ELEMENT(USE_DISK),
- PROCESSOR_BATCH_SIZE_ELEMENT(PROCESSOR_BATCH_SIZE),
- CONNECTOR_BATCH_SIZE_ELEMENT(CONNECTOR_BATCH_SIZE),
- MAX_PROCESSING_KB_ELEMENT(MAX_PROCESSING_KB),
- MAX_RESERVED_KB_ELEMENT(MAX_RESERVED_KB),
- MAX_FILE_SIZE_ELEMENT(MAX_FILE_SIZE),
- MAX_BUFFER_SPACE_ELEMENT(MAX_BUFFER_SPACE),
- MAX_OPEN_FILES_ELEMENT(MAX_OPEN_FILES),
+ USE_DISK_ELEMENT(USE_DISK, BUFFER_SERVICE),
+ PROCESSOR_BATCH_SIZE_ELEMENT(PROCESSOR_BATCH_SIZE, BUFFER_SERVICE),
+ CONNECTOR_BATCH_SIZE_ELEMENT(CONNECTOR_BATCH_SIZE, BUFFER_SERVICE),
+ MAX_PROCESSING_KB_ELEMENT(MAX_PROCESSING_KB, BUFFER_SERVICE),
+ MAX_RESERVED_KB_ELEMENT(MAX_RESERVED_KB, BUFFER_SERVICE),
+ MAX_FILE_SIZE_ELEMENT(MAX_FILE_SIZE, BUFFER_SERVICE),
+ MAX_BUFFER_SPACE_ELEMENT(MAX_BUFFER_SPACE, BUFFER_SERVICE),
+ MAX_OPEN_FILES_ELEMENT(MAX_OPEN_FILES, BUFFER_SERVICE),
//prepared-plan-cache-config
- MAX_ENTRIES_ELEMENT(MAX_ENTRIES),
- MAX_AGE_IN_SECS_ELEMENT(MAX_AGE_IN_SECS),
- MAX_STALENESS_ELEMENT(MAX_STALENESS),
- ENABLE_ATTRIBUTE(ENABLE),
+ PPC_MAX_ENTRIES_ATTRIBUTE(MAX_ENTRIES, PREPAREDPLAN_CACHE),
+ PPC_MAX_AGE_IN_SECS_ATTRIBUTE(MAX_AGE_IN_SECS, PREPAREDPLAN_CACHE),
+ PPC_MAX_STALENESS_ATTRIBUTE(MAX_STALENESS, PREPAREDPLAN_CACHE),
+
// Object Replicator
- STACK_ATTRIBUTE(STACK),
- CLUSTER_NAME_ATTRIBUTE(CLUSTER_NAME),
+ OR_STACK_ATTRIBUTE(STACK, OBJECT_REPLICATOR),
+ OR_CLUSTER_NAME_ATTRIBUTE(CLUSTER_NAME, OBJECT_REPLICATOR),
- // cache-container
- NAME_ELEMENT(NAME),
- CONTAINER_NAME_ELEMENT(CONTAINER_NAME),
+ // Result set cache
+ RSC_ENABLE_ATTRIBUTE(ENABLE, RESULTSET_CACHE),
+ RSC_NAME_ELEMENT(NAME, RESULTSET_CACHE),
+ RSC_CONTAINER_NAME_ELEMENT(CONTAINER_NAME, RESULTSET_CACHE),
+ RSC_MAX_STALENESS_ELEMENT(MAX_STALENESS, RESULTSET_CACHE),
//socket config
- MAX_SOCKET_THREAD_SIZE_ELEMENT(MAX_SOCKET_THREAD_SIZE),
- IN_BUFFER_SIZE_ELEMENT(IN_BUFFER_SIZE),
- OUT_BUFFER_SIZE_ELEMENT(OUT_BUFFER_SIZE),
- SOCKET_BINDING_ELEMENT(SOCKET_BINDING),
- SSL_MODE_ELEMENT(SSL_MODE),
- KEY_STORE_FILE_ELEMENT(KEY_STORE_FILE),
- KEY_STORE_PASSWD_ELEMENT(KEY_STORE_PASSWD),
- KEY_STORE_TYPE_ELEMENT(KEY_STORE_TYPE),
- SSL_PROTOCOL_ELEMENT(SSL_PROTOCOL),
- KEY_MANAGEMENT_ALG_ELEMENT(KEY_MANAGEMENT_ALG),
- TRUST_FILE_ELEMENT(TRUST_FILE),
- TRUST_PASSWD_ELEMENT(TRUST_PASSWD),
- AUTH_MODE_ELEMENT(AUTH_MODE),
- SSL_ELEMENT(SSL),
-
- // Translator
+ JDBC_MAX_SOCKET_THREAD_SIZE_ATTRIBUTE(MAX_SOCKET_THREAD_SIZE,JDBC),
+ JDBC_IN_BUFFER_SIZE_ATTRIBUTE(IN_BUFFER_SIZE,JDBC),
+ JDBC_OUT_BUFFER_SIZE_ATTRIBUTE(OUT_BUFFER_SIZE,JDBC),
+ JDBC_SOCKET_BINDING_ATTRIBUTE(SOCKET_BINDING,JDBC),
+
+ JDBC_SSL_ELEMENT(SSL, JDBC),
+ JDBC_SSL_MODE_ELEMENT(SSL_MODE,JDBC,SSL),
+ JDBC_KEY_STORE_FILE_ELEMENT(KEY_STORE_FILE,JDBC,SSL),
+ JDBC_KEY_STORE_PASSWD_ELEMENT(KEY_STORE_PASSWD,JDBC,SSL),
+ JDBC_KEY_STORE_TYPE_ELEMENT(KEY_STORE_TYPE,JDBC,SSL),
+ JDBC_SSL_PROTOCOL_ELEMENT(SSL_PROTOCOL,JDBC,SSL),
+ JDBC_KEY_MANAGEMENT_ALG_ELEMENT(KEY_MANAGEMENT_ALG,JDBC,SSL),
+ JDBC_TRUST_FILE_ELEMENT(TRUST_FILE,JDBC,SSL),
+ JDBC_TRUST_PASSWD_ELEMENT(TRUST_PASSWD,JDBC,SSL),
+ JDBC_AUTH_MODE_ELEMENT(AUTH_MODE,JDBC,SSL),
+
+
+ ODBC_MAX_SOCKET_THREAD_SIZE_ATTRIBUTE(MAX_SOCKET_THREAD_SIZE,ODBC),
+ ODBC_IN_BUFFER_SIZE_ATTRIBUTE(IN_BUFFER_SIZE,ODBC),
+ ODBC_OUT_BUFFER_SIZE_ATTRIBUTE(OUT_BUFFER_SIZE,ODBC),
+ ODBC_SOCKET_BINDING_ATTRIBUTE(SOCKET_BINDING,ODBC),
+
+ ODBC_SSL_ELEMENT(SSL, ODBC),
+ ODBC_SSL_MODE_ELEMENT(SSL_MODE,ODBC,SSL),
+ ODBC_KEY_STORE_FILE_ELEMENT(KEY_STORE_FILE,ODBC,SSL),
+ ODBC_KEY_STORE_PASSWD_ELEMENT(KEY_STORE_PASSWD,ODBC,SSL),
+ ODBC_KEY_STORE_TYPE_ELEMENT(KEY_STORE_TYPE,ODBC,SSL),
+ ODBC_SSL_PROTOCOL_ELEMENT(SSL_PROTOCOL,ODBC,SSL),
+ ODBC_KEY_MANAGEMENT_ALG_ELEMENT(KEY_MANAGEMENT_ALG,ODBC,SSL),
+ ODBC_TRUST_FILE_ELEMENT(TRUST_FILE,ODBC,SSL),
+ ODBC_TRUST_PASSWD_ELEMENT(TRUST_PASSWD,ODBC,SSL),
+ ODBC_AUTH_MODE_ELEMENT(AUTH_MODE,ODBC,SSL),
+
+
+ // Translator
TRANSLATOR_ELEMENT(TRANSLATOR),
TRANSLATOR_NAME_ATTRIBUTE(TRANSLATOR_NAME),
TRANSLATOR_MODULE_ATTRIBUTE(TRANSLATOR_MODULE);
private final String name;
+ private String[] prefix;
- Element(final String name) {
+ Element(final String name, String... prefix) {
this.name = name;
+ this.prefix = prefix;
}
/**
@@ -121,20 +143,45 @@
public String getLocalName() {
return name;
}
+
+ public String getModelName() {
+ return buildModelName(this.name, this.prefix);
+ }
+
+ private static String buildModelName(String name, String... prefix) {
+ if (prefix == null || prefix.length == 0) {
+ return name;
+ }
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(prefix[0]);
+ for (int i = 1; i < prefix.length; i++) {
+ sb.append("-"); //$NON-NLS-1$
+ sb.append(prefix[i]);
+ }
+ sb.append("-"); //$NON-NLS-1$
+ sb.append(name);
+ return sb.toString();
+ }
+
+ public String[] getPrefix() {
+ return this.prefix;
+ }
private static final Map<String, Element> elements;
static {
final Map<String, Element> map = new HashMap<String, Element>();
for (Element element : values()) {
- final String name = element.getLocalName();
+ final String name = element.getModelName();
if (name != null) map.put(name, element);
}
elements = map;
}
- public static Element forName(String localName) {
- final Element element = elements.get(localName);
+ public static Element forName(String localName, String... prefix) {
+ String modelName = buildModelName(localName, prefix);
+ final Element element = elements.get(modelName);
return element == null ? UNKNOWN : element;
}
}
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/ObjectSerializer.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/ObjectSerializer.java 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/ObjectSerializer.java 2011-09-28 15:25:16 UTC (rev 3505)
@@ -122,7 +122,6 @@
public OutputStream getVdbXmlOutputStream(VDBMetaData vdb) throws IOException {
File f = buildVdbXml(vdb);
- f.mkdirs();
return new FileOutputStream(f);
}
}
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/QueryEngineAdd.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/QueryEngineAdd.java 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/QueryEngineAdd.java 2011-09-28 15:25:16 UTC (rev 3505)
@@ -72,18 +72,13 @@
node.get(OPERATION_NAME).set(ADD);
node.get(DESCRIPTION).set("engine.add"); //$NON-NLS-1$
- ModelNode engine = node.get(REQUEST_PROPERTIES, Configuration.QUERY_ENGINE);
- describeQueryEngine(engine, ATTRIBUTES, bundle);
+ describeQueryEngine(node, REQUEST_PROPERTIES, bundle);
return node;
}
@Override
protected void populateModel(ModelNode operation, ModelNode model) {
- final ModelNode address = operation.require(OP_ADDR);
- final PathAddress pathAddress = PathAddress.pathAddress(address);
- final String engineName = pathAddress.getLastElement().getValue();
-
- populate(engineName, operation, model);
+ populate(operation, model);
}
@Override
@@ -101,17 +96,14 @@
// now build the engine
final RuntimeEngineDeployer engine = buildQueryEngine(engineName, operation);
engine.setSecurityHelper(new JBossSecurityHelper());
- // TODO: none of the caching is configured..
- SocketConfiguration jdbc = null;
- if (operation.hasDefined(Configuration.JDBC)) {
- jdbc = buildSocketConfiguration(operation.get(Configuration.JDBC));
+ SocketConfiguration jdbc = buildSocketConfiguration(Configuration.JDBC, operation);
+ if (jdbc != null) {
engine.setJdbcSocketConfiguration(jdbc);
}
- SocketConfiguration odbc = null;
- if (operation.hasDefined(Configuration.ODBC)) {
- odbc = buildSocketConfiguration(operation.get(Configuration.ODBC));
+ SocketConfiguration odbc = buildSocketConfiguration(Configuration.ODBC, operation);
+ if (odbc != null) {
engine.setOdbcSocketConfiguration(odbc);
}
@@ -222,64 +214,61 @@
}
- private SocketConfiguration buildSocketConfiguration(ModelNode node) {
- SocketConfiguration socket = new SocketConfiguration();
+ private SocketConfiguration buildSocketConfiguration(String prefix, ModelNode node) {
- if (node.hasDefined(Configuration.SOCKET_BINDING)) {
- socket.setSocketBinding(node.require(Configuration.SOCKET_BINDING).asString());
+ if (!node.hasDefined(prefix+Configuration.SOCKET_BINDING)) {
+ return null;
}
- else {
- throw new IllegalArgumentException(IntegrationPlugin.Util.getString(Configuration.SOCKET_BINDING+".not_defined")); //$NON-NLS-1$
- }
+
+ SocketConfiguration socket = new SocketConfiguration();
+ socket.setSocketBinding(node.require(prefix+Configuration.SOCKET_BINDING).asString());
- if (node.hasDefined(Configuration.MAX_SOCKET_THREAD_SIZE)) {
- socket.setMaxSocketThreads(node.get(Configuration.MAX_SOCKET_THREAD_SIZE).asInt());
+ if (node.hasDefined(prefix+Configuration.MAX_SOCKET_THREAD_SIZE)) {
+ socket.setMaxSocketThreads(node.get(prefix+Configuration.MAX_SOCKET_THREAD_SIZE).asInt());
}
- if (node.hasDefined(Configuration.IN_BUFFER_SIZE)) {
- socket.setInputBufferSize(node.get(Configuration.IN_BUFFER_SIZE).asInt());
+ if (node.hasDefined(prefix+Configuration.IN_BUFFER_SIZE)) {
+ socket.setInputBufferSize(node.get(prefix+Configuration.IN_BUFFER_SIZE).asInt());
}
- if (node.hasDefined(Configuration.OUT_BUFFER_SIZE)) {
- socket.setOutputBufferSize(node.get(Configuration.OUT_BUFFER_SIZE).asInt());
+ if (node.hasDefined(prefix+Configuration.OUT_BUFFER_SIZE)) {
+ socket.setOutputBufferSize(node.get(prefix+Configuration.OUT_BUFFER_SIZE).asInt());
}
SSLConfiguration ssl = new SSLConfiguration();
ssl.setAuthenticationMode(SSLConfiguration.ANONYMOUS);
- if (node.hasDefined(Configuration.SSL)) {
- ModelNode sslNode = node.get(Configuration.SSL);
+ String sslPrefix = prefix+ Configuration.SSL +TeiidBootServicesAdd.DASH;
- if (sslNode.hasDefined(Configuration.SSL_MODE)) {
- ssl.setMode(sslNode.get(Configuration.SSL_MODE).asString());
- }
-
- if (sslNode.hasDefined(Configuration.KEY_STORE_FILE)) {
- ssl.setKeystoreFilename(sslNode.get(Configuration.KEY_STORE_FILE).asString());
- }
-
- if (sslNode.hasDefined(Configuration.KEY_STORE_PASSWD)) {
- ssl.setKeystorePassword(sslNode.get(Configuration.KEY_STORE_PASSWD).asString());
- }
-
- if (sslNode.hasDefined(Configuration.KEY_STORE_TYPE)) {
- ssl.setKeystoreType(sslNode.get(Configuration.KEY_STORE_TYPE).asString());
- }
-
- if (sslNode.hasDefined(Configuration.SSL_PROTOCOL)) {
- ssl.setSslProtocol(sslNode.get(Configuration.SSL_PROTOCOL).asString());
- }
- if (sslNode.hasDefined(Configuration.KEY_MANAGEMENT_ALG)) {
- ssl.setKeymanagementAlgorithm(sslNode.get(Configuration.KEY_MANAGEMENT_ALG).asString());
- }
- if (sslNode.hasDefined(Configuration.TRUST_FILE)) {
- ssl.setTruststoreFilename(sslNode.get(Configuration.TRUST_FILE).asString());
- }
- if (sslNode.hasDefined(Configuration.TRUST_PASSWD)) {
- ssl.setTruststorePassword(sslNode.get(Configuration.TRUST_PASSWD).asString());
- }
- if (sslNode.hasDefined(Configuration.AUTH_MODE)) {
- ssl.setAuthenticationMode(sslNode.get(Configuration.AUTH_MODE).asString());
- }
+ if (node.hasDefined(sslPrefix+Configuration.SSL_MODE)) {
+ ssl.setMode(node.get(sslPrefix+Configuration.SSL_MODE).asString());
}
+
+ if (node.hasDefined(sslPrefix+Configuration.KEY_STORE_FILE)) {
+ ssl.setKeystoreFilename(node.get(sslPrefix+Configuration.KEY_STORE_FILE).asString());
+ }
+
+ if (node.hasDefined(sslPrefix+Configuration.KEY_STORE_PASSWD)) {
+ ssl.setKeystorePassword(node.get(sslPrefix+Configuration.KEY_STORE_PASSWD).asString());
+ }
+
+ if (node.hasDefined(sslPrefix+Configuration.KEY_STORE_TYPE)) {
+ ssl.setKeystoreType(node.get(sslPrefix+Configuration.KEY_STORE_TYPE).asString());
+ }
+
+ if (node.hasDefined(sslPrefix+Configuration.SSL_PROTOCOL)) {
+ ssl.setSslProtocol(node.get(sslPrefix+Configuration.SSL_PROTOCOL).asString());
+ }
+ if (node.hasDefined(sslPrefix+Configuration.KEY_MANAGEMENT_ALG)) {
+ ssl.setKeymanagementAlgorithm(node.get(sslPrefix+Configuration.KEY_MANAGEMENT_ALG).asString());
+ }
+ if (node.hasDefined(sslPrefix+Configuration.TRUST_FILE)) {
+ ssl.setTruststoreFilename(node.get(sslPrefix+Configuration.TRUST_FILE).asString());
+ }
+ if (node.hasDefined(sslPrefix+Configuration.TRUST_PASSWD)) {
+ ssl.setTruststorePassword(node.get(sslPrefix+Configuration.TRUST_PASSWD).asString());
+ }
+ if (node.hasDefined(sslPrefix+Configuration.AUTH_MODE)) {
+ ssl.setAuthenticationMode(node.get(sslPrefix+Configuration.AUTH_MODE).asString());
+ }
socket.setSSLConfiguration(ssl);
return socket;
@@ -304,50 +293,34 @@
addAttribute(node, Configuration.SESSION_EXPIRATION_TIME_LIMIT, type, bundle.getString(Configuration.SESSION_EXPIRATION_TIME_LIMIT+DESC), ModelType.INT, false, "0"); //$NON-NLS-1$
//jdbc
- ModelNode jdbcSocketNode = node.get(CHILDREN, Configuration.JDBC);
- jdbcSocketNode.get(TYPE).set(ModelType.OBJECT);
- jdbcSocketNode.get(DESCRIPTION).set(bundle.getString(Configuration.JDBC+DESC));
- jdbcSocketNode.get(REQUIRED).set(false);
- jdbcSocketNode.get(MAX_OCCURS).set(1);
- jdbcSocketNode.get(MIN_OCCURS).set(1);
- describeSocketConfig(jdbcSocketNode, type, bundle);
+ describeSocketConfig(Configuration.JDBC+TeiidBootServicesAdd.DASH, node, type, bundle);
//odbc
- ModelNode odbcSocketNode = node.get(CHILDREN, Configuration.ODBC);
- odbcSocketNode.get(TYPE).set(ModelType.OBJECT);
- odbcSocketNode.get(DESCRIPTION).set(bundle.getString(Configuration.ODBC+DESC));
- odbcSocketNode.get(REQUIRED).set(false);
- odbcSocketNode.get(MAX_OCCURS).set(1);
- odbcSocketNode.get(MIN_OCCURS).set(1);
- describeSocketConfig(odbcSocketNode, type, bundle);
+ describeSocketConfig(Configuration.ODBC+TeiidBootServicesAdd.DASH, node, type, bundle);
}
- private static void describeSocketConfig(ModelNode node, String type, ResourceBundle bundle) {
- addAttribute(node, Configuration.MAX_SOCKET_THREAD_SIZE, type, bundle.getString(Configuration.MAX_SOCKET_THREAD_SIZE+DESC), ModelType.INT, false, "0"); //$NON-NLS-1$
- addAttribute(node, Configuration.IN_BUFFER_SIZE, type, bundle.getString(Configuration.IN_BUFFER_SIZE+DESC), ModelType.INT, false, "0"); //$NON-NLS-1$
- addAttribute(node, Configuration.OUT_BUFFER_SIZE, type, bundle.getString(Configuration.OUT_BUFFER_SIZE+DESC), ModelType.INT, false, "0"); //$NON-NLS-1$
- addAttribute(node, Configuration.SOCKET_BINDING, type, bundle.getString(Configuration.SOCKET_BINDING+DESC), ModelType.STRING, true, null);
+ private static void describeSocketConfig(String prefix, ModelNode node, String type, ResourceBundle bundle) {
+ addAttribute(node, prefix+Configuration.MAX_SOCKET_THREAD_SIZE, type, bundle.getString(Configuration.MAX_SOCKET_THREAD_SIZE+DESC), ModelType.INT, false, "0"); //$NON-NLS-1$
+ addAttribute(node, prefix+Configuration.IN_BUFFER_SIZE, type, bundle.getString(Configuration.IN_BUFFER_SIZE+DESC), ModelType.INT, false, "0"); //$NON-NLS-1$
+ addAttribute(node, prefix+Configuration.OUT_BUFFER_SIZE, type, bundle.getString(Configuration.OUT_BUFFER_SIZE+DESC), ModelType.INT, false, "0"); //$NON-NLS-1$
+ addAttribute(node, prefix+Configuration.SOCKET_BINDING, type, bundle.getString(Configuration.SOCKET_BINDING+DESC), ModelType.STRING, false, null);
- ModelNode sslNode = node.get(CHILDREN, Configuration.SSL);
- sslNode.get(TYPE).set(ModelType.OBJECT);
- sslNode.get(DESCRIPTION).set(bundle.getString(Configuration.SSL+DESC));
- sslNode.get(REQUIRED).set(false);
- sslNode.get(MAX_OCCURS).set(1);
- sslNode.get(MIN_OCCURS).set(0);
- addAttribute(node, Configuration.SSL_MODE, type, bundle.getString(Configuration.SSL_MODE+DESC), ModelType.STRING, false, "login"); //$NON-NLS-1$
- addAttribute(node, Configuration.KEY_STORE_FILE, type, bundle.getString(Configuration.KEY_STORE_FILE+DESC), ModelType.STRING, false, null);
- addAttribute(node, Configuration.KEY_STORE_PASSWD, type, bundle.getString(Configuration.KEY_STORE_PASSWD+DESC), ModelType.STRING, false, null);
- addAttribute(node, Configuration.KEY_STORE_TYPE, type, bundle.getString(Configuration.KEY_STORE_TYPE+DESC), ModelType.STRING, false, "JKS"); //$NON-NLS-1$
- addAttribute(node, Configuration.SSL_PROTOCOL, type, bundle.getString(Configuration.SSL_PROTOCOL+DESC), ModelType.BOOLEAN, false, "SSLv3"); //$NON-NLS-1$
- addAttribute(node, Configuration.KEY_MANAGEMENT_ALG, type, bundle.getString(Configuration.KEY_MANAGEMENT_ALG+DESC), ModelType.STRING, false, "false"); //$NON-NLS-1$
- addAttribute(node, Configuration.TRUST_FILE, type, bundle.getString(Configuration.TRUST_FILE+DESC), ModelType.STRING, false, null);
- addAttribute(node, Configuration.TRUST_PASSWD, type, bundle.getString(Configuration.TRUST_PASSWD+DESC), ModelType.STRING, false, null);
- addAttribute(node, Configuration.AUTH_MODE, type, bundle.getString(Configuration.AUTH_MODE+DESC), ModelType.STRING, false, "anonymous"); //$NON-NLS-1$
+ String sslPrefix = prefix+Configuration.SSL+TeiidBootServicesAdd.DASH;
+
+ addAttribute(node, sslPrefix+Configuration.SSL_MODE, type, bundle.getString(Configuration.SSL_MODE+DESC), ModelType.STRING, false, "login"); //$NON-NLS-1$
+ addAttribute(node, sslPrefix+Configuration.KEY_STORE_FILE, type, bundle.getString(Configuration.KEY_STORE_FILE+DESC), ModelType.STRING, false, null);
+ addAttribute(node, sslPrefix+Configuration.KEY_STORE_PASSWD, type, bundle.getString(Configuration.KEY_STORE_PASSWD+DESC), ModelType.STRING, false, null);
+ addAttribute(node, sslPrefix+Configuration.KEY_STORE_TYPE, type, bundle.getString(Configuration.KEY_STORE_TYPE+DESC), ModelType.STRING, false, "JKS"); //$NON-NLS-1$
+ addAttribute(node, sslPrefix+Configuration.SSL_PROTOCOL, type, bundle.getString(Configuration.SSL_PROTOCOL+DESC), ModelType.STRING, false, "SSLv3"); //$NON-NLS-1$
+ addAttribute(node, sslPrefix+Configuration.KEY_MANAGEMENT_ALG, type, bundle.getString(Configuration.KEY_MANAGEMENT_ALG+DESC), ModelType.STRING, false, null);
+ addAttribute(node, sslPrefix+Configuration.TRUST_FILE, type, bundle.getString(Configuration.TRUST_FILE+DESC), ModelType.STRING, false, null);
+ addAttribute(node, sslPrefix+Configuration.TRUST_PASSWD, type, bundle.getString(Configuration.TRUST_PASSWD+DESC), ModelType.STRING, false, null);
+ addAttribute(node, sslPrefix+Configuration.AUTH_MODE, type, bundle.getString(Configuration.AUTH_MODE+DESC), ModelType.STRING, false, "anonymous"); //$NON-NLS-1$
}
- static void populate(String engineName, ModelNode operation, ModelNode model) {
- model.get(Configuration.ENGINE_NAME).set(engineName);
+ static void populate(ModelNode operation, ModelNode model) {
+ //model.get(Configuration.ENGINE_NAME).set(engineName);
if (operation.hasDefined(Configuration.MAX_THREADS)) {
model.get(Configuration.MAX_THREADS).set(operation.get(Configuration.MAX_THREADS).asInt());
@@ -395,65 +368,57 @@
model.get(Configuration.MAX_SESSIONS_ALLOWED).set(operation.get(Configuration.MAX_SESSIONS_ALLOWED).asInt());
}
- if (operation.hasDefined(Configuration.JDBC)) {
- populateSocketConfiguration(operation.get(Configuration.JDBC), model.get(Configuration.JDBC));
- }
-
- if (operation.hasDefined(Configuration.ODBC)) {
- populateSocketConfiguration(operation.get(Configuration.ODBC), model.get(Configuration.ODBC));
- }
+ populateSocketConfiguration(Configuration.JDBC+TeiidBootServicesAdd.DASH, operation, model);
+
+ populateSocketConfiguration(Configuration.ODBC+TeiidBootServicesAdd.DASH, operation, model);
}
- private static void populateSocketConfiguration(ModelNode operation, ModelNode model) {
- if (operation.hasDefined(Configuration.SOCKET_BINDING)) {
- model.get(Configuration.SOCKET_BINDING).set(operation.get(Configuration.SOCKET_BINDING).asString());
+ private static void populateSocketConfiguration(String prefix, ModelNode operation, ModelNode model) {
+ if (operation.hasDefined(prefix+Configuration.SOCKET_BINDING)) {
+ model.get(prefix+Configuration.SOCKET_BINDING).set(operation.get(prefix+Configuration.SOCKET_BINDING).asString());
}
- if (operation.hasDefined(Configuration.MAX_SOCKET_THREAD_SIZE)) {
- model.get(Configuration.MAX_SOCKET_THREAD_SIZE).set(operation.get(Configuration.MAX_SOCKET_THREAD_SIZE).asInt());
+ if (operation.hasDefined(prefix+Configuration.MAX_SOCKET_THREAD_SIZE)) {
+ model.get(prefix+Configuration.MAX_SOCKET_THREAD_SIZE).set(operation.get(prefix+Configuration.MAX_SOCKET_THREAD_SIZE).asInt());
}
- if (operation.hasDefined(Configuration.IN_BUFFER_SIZE)) {
- model.get(Configuration.IN_BUFFER_SIZE).set(operation.get(Configuration.IN_BUFFER_SIZE).asInt());
+ if (operation.hasDefined(prefix+Configuration.IN_BUFFER_SIZE)) {
+ model.get(prefix+Configuration.IN_BUFFER_SIZE).set(operation.get(prefix+Configuration.IN_BUFFER_SIZE).asInt());
}
- if (operation.hasDefined(Configuration.OUT_BUFFER_SIZE)) {
- model.get(Configuration.OUT_BUFFER_SIZE).set(operation.get(Configuration.OUT_BUFFER_SIZE).asInt());
+ if (operation.hasDefined(prefix+Configuration.OUT_BUFFER_SIZE)) {
+ model.get(prefix+Configuration.OUT_BUFFER_SIZE).set(operation.get(prefix+Configuration.OUT_BUFFER_SIZE).asInt());
}
+ String sslPrefix = prefix+Configuration.SSL+TeiidBootServicesAdd.DASH;
- if (operation.hasDefined(Configuration.SSL)) {
- operation = operation.get(Configuration.SSL);
- model = model.get(Configuration.SSL);
-
- if (operation.hasDefined(Configuration.SSL_MODE)) {
- model.get(Configuration.SSL_MODE).set(operation.get(Configuration.SSL_MODE).asString());
- }
-
- if (operation.hasDefined(Configuration.KEY_STORE_FILE)) {
- model.get(Configuration.KEY_STORE_FILE).set(operation.get(Configuration.KEY_STORE_FILE).asString());
- }
-
- if (operation.hasDefined(Configuration.KEY_STORE_PASSWD)) {
- model.get(Configuration.KEY_STORE_PASSWD).set(operation.get(Configuration.KEY_STORE_PASSWD).asString());
- }
-
- if (operation.hasDefined(Configuration.KEY_STORE_TYPE)) {
- model.get(Configuration.KEY_STORE_TYPE).set(operation.get(Configuration.KEY_STORE_TYPE).asString());
- }
-
- if (operation.hasDefined(Configuration.SSL_PROTOCOL)) {
- model.get(Configuration.SSL_PROTOCOL).set(operation.get(Configuration.SSL_PROTOCOL).asString());
- }
- if (operation.hasDefined(Configuration.KEY_MANAGEMENT_ALG)) {
- model.get(Configuration.KEY_MANAGEMENT_ALG).set(operation.get(Configuration.KEY_MANAGEMENT_ALG).asString());
- }
- if (operation.hasDefined(Configuration.TRUST_FILE)) {
- model.get(Configuration.TRUST_FILE).set(operation.get(Configuration.TRUST_FILE).asString());
- }
- if (operation.hasDefined(Configuration.TRUST_PASSWD)) {
- model.get(Configuration.TRUST_PASSWD).set(operation.get(Configuration.TRUST_PASSWD).asString());
- }
- if (operation.hasDefined(Configuration.AUTH_MODE)) {
- model.get(Configuration.AUTH_MODE).set(operation.get(Configuration.AUTH_MODE).asString());
- }
+ if (operation.hasDefined(sslPrefix+Configuration.SSL_MODE)) {
+ model.get(sslPrefix+Configuration.SSL_MODE).set(operation.get(sslPrefix+Configuration.SSL_MODE).asString());
}
+
+ if (operation.hasDefined(sslPrefix+Configuration.KEY_STORE_FILE)) {
+ model.get(sslPrefix+Configuration.KEY_STORE_FILE).set(operation.get(sslPrefix+Configuration.KEY_STORE_FILE).asString());
+ }
+
+ if (operation.hasDefined(sslPrefix+Configuration.KEY_STORE_PASSWD)) {
+ model.get(sslPrefix+Configuration.KEY_STORE_PASSWD).set(operation.get(sslPrefix+Configuration.KEY_STORE_PASSWD).asString());
+ }
+
+ if (operation.hasDefined(sslPrefix+Configuration.KEY_STORE_TYPE)) {
+ model.get(sslPrefix+Configuration.KEY_STORE_TYPE).set(operation.get(sslPrefix+Configuration.KEY_STORE_TYPE).asString());
+ }
+
+ if (operation.hasDefined(sslPrefix+Configuration.SSL_PROTOCOL)) {
+ model.get(sslPrefix+Configuration.SSL_PROTOCOL).set(operation.get(sslPrefix+Configuration.SSL_PROTOCOL).asString());
+ }
+ if (operation.hasDefined(sslPrefix+Configuration.KEY_MANAGEMENT_ALG)) {
+ model.get(sslPrefix+Configuration.KEY_MANAGEMENT_ALG).set(operation.get(sslPrefix+Configuration.KEY_MANAGEMENT_ALG).asString());
+ }
+ if (operation.hasDefined(sslPrefix+Configuration.TRUST_FILE)) {
+ model.get(sslPrefix+Configuration.TRUST_FILE).set(operation.get(sslPrefix+Configuration.TRUST_FILE).asString());
+ }
+ if (operation.hasDefined(sslPrefix+Configuration.TRUST_PASSWD)) {
+ model.get(sslPrefix+Configuration.TRUST_PASSWD).set(operation.get(sslPrefix+Configuration.TRUST_PASSWD).asString());
+ }
+ if (operation.hasDefined(sslPrefix+Configuration.AUTH_MODE)) {
+ model.get(sslPrefix+Configuration.AUTH_MODE).set(operation.get(sslPrefix+Configuration.AUTH_MODE).asString());
+ }
}
}
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/QueryEngineOperationHandler.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/QueryEngineOperationHandler.java 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/QueryEngineOperationHandler.java 2011-09-28 15:25:16 UTC (rev 3505)
@@ -23,10 +23,13 @@
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.*;
+import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.ResourceBundle;
+import javax.xml.stream.XMLStreamException;
+
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
@@ -36,7 +39,6 @@
import org.teiid.adminapi.Admin;
import org.teiid.adminapi.AdminException;
import org.teiid.adminapi.AdminProcessingException;
-import org.teiid.adminapi.VDB;
import org.teiid.adminapi.impl.*;
import org.teiid.adminapi.impl.VDBMetadataMapper.TransactionMetadataMapper;
import org.teiid.adminapi.impl.VDBMetadataMapper.VDBTranslatorMetaDataMapper;
@@ -707,12 +709,15 @@
}
}
-abstract class VDBOperations extends BaseOperationHandler<VDBService>{
+abstract class VDBOperations extends BaseOperationHandler<VDBMetaData>{
+ private ObjectSerializer serializer;
+
public VDBOperations(String operationName) {
super(operationName);
}
+
@Override
- public VDBService getService(OperationContext context, PathAddress pathAddress, ModelNode operation) throws OperationFailedException {
+ public VDBMetaData getService(OperationContext context, PathAddress pathAddress, ModelNode operation) throws OperationFailedException {
if (!operation.hasDefined(OperationsConstants.VDB_NAME)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.VDB_NAME+MISSING)));
}
@@ -723,8 +728,12 @@
String vdbName = operation.get(OperationsConstants.VDB_NAME).asString();
int vdbVersion = operation.get(OperationsConstants.VDB_VERSION).asInt();
+
+ ServiceController<?> osSvc = context.getServiceRegistry(false).getRequiredService(TeiidServiceNames.OBJECT_SERIALIZER);
+ this.serializer = ObjectSerializer.class.cast(osSvc.getValue());
+
ServiceController<?> sc = context.getServiceRegistry(false).getRequiredService(TeiidServiceNames.vdbServiceName(vdbName, vdbVersion));
- return VDBService.class.cast(sc.getValue());
+ return VDBMetaData.class.cast(sc.getValue());
}
protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
@@ -736,6 +745,16 @@
operationNode.get(REQUEST_PROPERTIES, OperationsConstants.VDB_VERSION, REQUIRED).set(true);
operationNode.get(REQUEST_PROPERTIES, OperationsConstants.VDB_VERSION, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.VDB_VERSION));
}
+
+ protected void save(VDBMetaData vdb) throws AdminProcessingException{
+ try {
+ VDBMetadataParser.marshell(vdb, this.serializer.getVdbXmlOutputStream(vdb));
+ } catch (IOException e) {
+ throw new AdminProcessingException(e);
+ } catch (XMLStreamException e) {
+ throw new AdminProcessingException(e);
+ }
+ }
}
class AddDataRole extends VDBOperations {
@@ -745,7 +764,7 @@
}
@Override
- protected void executeOperation(OperationContext context, VDBService service, ModelNode operation) throws OperationFailedException {
+ protected void executeOperation(OperationContext context, VDBMetaData vdb, ModelNode operation) throws OperationFailedException {
if (!operation.hasDefined(OperationsConstants.DATA_ROLE)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.DATA_ROLE+MISSING)));
}
@@ -754,11 +773,18 @@
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.MAPPED_ROLE+MISSING)));
}
- String dataRole = operation.get(OperationsConstants.DATA_ROLE).asString();
+ String policyName = operation.get(OperationsConstants.DATA_ROLE).asString();
String mappedRole = operation.get(OperationsConstants.MAPPED_ROLE).asString();
try {
- service.addDataRole(dataRole, mappedRole);
+ DataPolicyMetadata policy = vdb.getDataPolicy(policyName);
+
+ if (policy == null) {
+ throw new AdminProcessingException(IntegrationPlugin.Util.getString("policy_not_found", policyName, vdb.getName(), vdb.getVersion())); //$NON-NLS-1$
+ }
+
+ policy.addMappedRoleName(mappedRole);
+ save(vdb);
} catch (AdminProcessingException e) {
throw new OperationFailedException(new ModelNode().set(e.getMessage()));
}
@@ -785,7 +811,7 @@
}
@Override
- protected void executeOperation(OperationContext context, VDBService service, ModelNode operation) throws OperationFailedException {
+ protected void executeOperation(OperationContext context, VDBMetaData vdb, ModelNode operation) throws OperationFailedException {
if (!operation.hasDefined(OperationsConstants.DATA_ROLE)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.DATA_ROLE+MISSING)));
}
@@ -794,11 +820,18 @@
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.MAPPED_ROLE+MISSING)));
}
- String dataRole = operation.get(OperationsConstants.DATA_ROLE).asString();
+ String policyName = operation.get(OperationsConstants.DATA_ROLE).asString();
String mappedRole = operation.get(OperationsConstants.MAPPED_ROLE).asString();
try {
- service.addDataRole(dataRole, mappedRole);
+ DataPolicyMetadata policy = vdb.getDataPolicy(policyName);
+
+ if (policy == null) {
+ throw new AdminProcessingException(IntegrationPlugin.Util.getString("policy_not_found", policyName, vdb.getName(), vdb.getVersion())); //$NON-NLS-1$
+ }
+
+ policy.removeMappedRoleName(mappedRole);
+ save(vdb);
} catch (AdminProcessingException e) {
throw new OperationFailedException(new ModelNode().set(e.getMessage()));
}
@@ -825,15 +858,22 @@
}
@Override
- protected void executeOperation(OperationContext context, VDBService service, ModelNode operation) throws OperationFailedException {
+ protected void executeOperation(OperationContext context, VDBMetaData vdb, ModelNode operation) throws OperationFailedException {
if (!operation.hasDefined(OperationsConstants.DATA_ROLE)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.DATA_ROLE+MISSING)));
}
- String dataRole = operation.get(OperationsConstants.DATA_ROLE).asString();
+ String policyName = operation.get(OperationsConstants.DATA_ROLE).asString();
try {
- service.addAnyAuthenticated(dataRole);
+ DataPolicyMetadata policy = vdb.getDataPolicy(policyName);
+
+ if (policy == null) {
+ throw new AdminProcessingException(IntegrationPlugin.Util.getString("policy_not_found", policyName, vdb.getName(), vdb.getVersion())); //$NON-NLS-1$
+ }
+
+ policy.setAnyAuthenticated(true);
+ save(vdb);
} catch (AdminProcessingException e) {
throw new OperationFailedException(new ModelNode().set(e.getMessage()));
}
@@ -857,15 +897,22 @@
}
@Override
- protected void executeOperation(OperationContext context, VDBService service, ModelNode operation) throws OperationFailedException {
+ protected void executeOperation(OperationContext context, VDBMetaData vdb, ModelNode operation) throws OperationFailedException {
if (!operation.hasDefined(OperationsConstants.DATA_ROLE)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.DATA_ROLE+MISSING)));
}
- String dataRole = operation.get(OperationsConstants.DATA_ROLE).asString();
+ String policyName = operation.get(OperationsConstants.DATA_ROLE).asString();
try {
- service.removeAnyAuthenticated(dataRole);
+ DataPolicyMetadata policy = vdb.getDataPolicy(policyName);
+
+ if (policy == null) {
+ throw new AdminProcessingException(IntegrationPlugin.Util.getString("policy_not_found", policyName, vdb.getName(), vdb.getVersion())); //$NON-NLS-1$
+ }
+
+ policy.setAnyAuthenticated(false);
+ save(vdb);
} catch (AdminProcessingException e) {
throw new OperationFailedException(new ModelNode().set(e.getMessage()));
}
@@ -888,14 +935,15 @@
}
@Override
- protected void executeOperation(OperationContext context, VDBService service, ModelNode operation) throws OperationFailedException {
+ protected void executeOperation(OperationContext context, VDBMetaData vdb, ModelNode operation) throws OperationFailedException {
if (!operation.hasDefined(OperationsConstants.CONNECTION_TYPE)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.CONNECTION_TYPE+MISSING)));
}
String connectionType = operation.get(OperationsConstants.CONNECTION_TYPE).asString();
try {
- service.changeConnectionType(VDB.ConnectionType.valueOf(connectionType));
+ vdb.setConnectionType(connectionType);
+ save(vdb);
} catch (AdminProcessingException e) {
throw new OperationFailedException(new ModelNode().set(e.getMessage()));
}
@@ -918,7 +966,7 @@
}
@Override
- protected void executeOperation(OperationContext context, VDBService service, ModelNode operation) throws OperationFailedException {
+ protected void executeOperation(OperationContext context, VDBMetaData vdb, ModelNode operation) throws OperationFailedException {
if (!operation.hasDefined(OperationsConstants.MODEL_NAME)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.MODEL_NAME+MISSING)));
}
@@ -942,7 +990,19 @@
String dsName = operation.get(OperationsConstants.DS_NAME).asString();
try {
- service.assignDatasource(modelName, sourceName, translatorName, dsName);
+ ModelMetaData model = vdb.getModel(modelName);
+
+ if (model == null) {
+ throw new AdminProcessingException(IntegrationPlugin.Util.getString("model_not_found", modelName, vdb.getName(), vdb.getVersion())); //$NON-NLS-1$
+ }
+
+ SourceMappingMetadata source = model.getSourceMapping(sourceName);
+ if(source == null) {
+ throw new AdminProcessingException(IntegrationPlugin.Util.getString("source_not_found", sourceName, modelName, vdb.getName(), vdb.getVersion())); //$NON-NLS-1$
+ }
+ source.setTranslatorName(translatorName);
+ source.setConnectionJndiName(dsName);
+ save(vdb);
} catch (AdminProcessingException e) {
throw new OperationFailedException(new ModelNode().set(e.getMessage()));
}
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidBootServicesAdd.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidBootServicesAdd.java 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidBootServicesAdd.java 2011-09-28 15:25:16 UTC (rev 3505)
@@ -63,6 +63,8 @@
class TeiidBootServicesAdd extends AbstractAddStepHandler implements DescriptionProvider {
+ static final String DASH = "-"; //$NON-NLS-1$
+
@Override
public ModelNode getModelDescription(Locale locale) {
final ResourceBundle bundle = IntegrationPlugin.getResourceBundle(locale);
@@ -81,27 +83,11 @@
addAttribute(node, Configuration.AUTHORIZATION_VALIDATOR_MODULE, type, bundle.getString(Configuration.AUTHORIZATION_VALIDATOR_MODULE+DESC), ModelType.BOOLEAN, false, null);
addAttribute(node, Configuration.POLICY_DECIDER_MODULE, type, bundle.getString(Configuration.POLICY_DECIDER_MODULE+DESC), ModelType.STRING, false, null);
- addAttribute(node, Configuration.OBJECT_REPLICATOR, type, bundle.getString(Configuration.OBJECT_REPLICATOR+DESC), ModelType.STRING, false, null);
- ModelNode bufferNode = node.get(CHILDREN, Configuration.BUFFER_SERVICE);
- bufferNode.get(TYPE).set(ModelType.OBJECT);
- bufferNode.get(DESCRIPTION).set(bundle.getString(Configuration.BUFFER_SERVICE+DESC));
- bufferNode.get(REQUIRED).set(false);
- describeBufferManager(bufferNode, ATTRIBUTES, bundle);
-
- // preparedplan-set-cache
- ModelNode preparedPlanCacheNode = node.get(CHILDREN, Configuration.PREPAREDPLAN_CACHE);
- preparedPlanCacheNode.get(TYPE).set(ModelType.OBJECT);
- preparedPlanCacheNode.get(DESCRIPTION).set(bundle.getString(Configuration.PREPAREDPLAN_CACHE+DESC));
- preparedPlanCacheNode.get(REQUIRED).set(false);
- describePreparedPlanCache(preparedPlanCacheNode, ATTRIBUTES, bundle);
-
- // result-set-cache
- ModelNode distributedCacheNode = node.get(CHILDREN, Configuration.RESULTSET_CACHE);
- distributedCacheNode.get(TYPE).set(ModelType.OBJECT);
- distributedCacheNode.get(DESCRIPTION).set(bundle.getString(Configuration.RESULTSET_CACHE+DESC));
- distributedCacheNode.get(REQUIRED).set(false);
- describeResultsetCache(preparedPlanCacheNode, ATTRIBUTES, bundle);
+ describeObjectReplicator(node, type, bundle);
+ describeBufferManager(node, type, bundle);
+ describePreparedPlanCache(node, type, bundle);
+ describeResultsetCache(node, type, bundle);
}
@Override
@@ -182,7 +168,7 @@
// TODO: remove verbose service by moving the buffer service from runtime project
newControllers.add(RelativePathService.addService(TeiidServiceNames.BUFFER_DIR, "teiid-buffer", "jboss.server.temp.dir", target)); //$NON-NLS-1$ //$NON-NLS-2$
- final BufferServiceImpl bufferManager = buildBufferManager(operation.get(Configuration.BUFFER_SERVICE));
+ final BufferServiceImpl bufferManager = buildBufferManager(operation);
BufferManagerService bufferService = new BufferManagerService(bufferManager);
ServiceBuilder<BufferServiceImpl> bufferServiceBuilder = target.addService(TeiidServiceNames.BUFFER_MGR, bufferService);
bufferServiceBuilder.addDependency(TeiidServiceNames.BUFFER_DIR, String.class, bufferService.pathInjector);
@@ -230,7 +216,7 @@
newControllers.add(target.addService(TeiidServiceNames.CACHE_RESULTSET, resultSetService).install());
// prepared-plan cache
- final SessionAwareCache<PreparedPlan> preparedPlanCache = buildPreparedPlanCache(operation.get(Configuration.PREPAREDPLAN_CACHE), bufferManager.getBufferManager());
+ final SessionAwareCache<PreparedPlan> preparedPlanCache = buildPreparedPlanCache(operation, bufferManager.getBufferManager());
ValueService<SessionAwareCache<PreparedPlan>> preparedPlanService = new ValueService<SessionAwareCache<PreparedPlan>>(new org.jboss.msc.value.Value<SessionAwareCache<PreparedPlan>>() {
@Override
public SessionAwareCache<PreparedPlan> getValue() throws IllegalStateException, IllegalArgumentException {
@@ -240,12 +226,11 @@
newControllers.add(target.addService(TeiidServiceNames.CACHE_PREPAREDPLAN, preparedPlanService).install());
// Object Replicator
- if (operation.hasDefined(Configuration.OBJECT_REPLICATOR)) {
- ModelNode node = operation.get(Configuration.OBJECT_REPLICATOR);
- String stack = node.get(Configuration.STACK).asString();
+ if (operation.hasDefined(ORC(Configuration.STACK))) {
+ String stack = operation.get(ORC(Configuration.STACK)).asString();
String clusterName = "teiid-rep"; //$NON-NLS-1$
- if (node.hasDefined(Configuration.CLUSTER_NAME)) {
- clusterName = node.get(Configuration.CLUSTER_NAME).asString();
+ if (operation.hasDefined(ORC(Configuration.CLUSTER_NAME))) {
+ clusterName = operation.get(ORC(Configuration.CLUSTER_NAME)).asString();
}
JGroupsObjectReplicatorService replicatorService = new JGroupsObjectReplicatorService(clusterName);
replicatorService.setBufferManager(bufferManager.getBufferManager());
@@ -282,17 +267,27 @@
return services.iterator().next();
}
-
+ private static String BS(String name) {
+ return Configuration.BUFFER_SERVICE+DASH+name;
+ }
static void describeBufferManager(ModelNode node, String type, ResourceBundle bundle) {
- addAttribute(node, Configuration.USE_DISK, type, bundle.getString(Configuration.USE_DISK+DESC), ModelType.BOOLEAN, false, "true"); //$NON-NLS-1$
- addAttribute(node, Configuration.PROCESSOR_BATCH_SIZE, type, bundle.getString(Configuration.PROCESSOR_BATCH_SIZE+DESC), ModelType.INT, false, "512"); //$NON-NLS-1$
- addAttribute(node, Configuration.CONNECTOR_BATCH_SIZE, type, bundle.getString(Configuration.CONNECTOR_BATCH_SIZE+DESC), ModelType.INT, false, "1024"); //$NON-NLS-1$
- addAttribute(node, Configuration.MAX_PROCESSING_KB, type, bundle.getString(Configuration.MAX_PROCESSING_KB+DESC), ModelType.INT, false, "-1"); //$NON-NLS-1$
- addAttribute(node, Configuration.MAX_RESERVED_KB, type, bundle.getString(Configuration.MAX_RESERVED_KB+DESC), ModelType.INT, false, "-1"); //$NON-NLS-1$
- addAttribute(node, Configuration.MAX_FILE_SIZE, type, bundle.getString(Configuration.MAX_FILE_SIZE+DESC), ModelType.LONG, false, "2048"); //$NON-NLS-1$
- addAttribute(node, Configuration.MAX_BUFFER_SPACE, type, bundle.getString(Configuration.MAX_BUFFER_SPACE+DESC), ModelType.LONG, false, "51200"); //$NON-NLS-1$
- addAttribute(node, Configuration.MAX_OPEN_FILES, type, bundle.getString(Configuration.MAX_OPEN_FILES+DESC), ModelType.INT, false, "64"); //$NON-NLS-1$
+ addAttribute(node, BS(Configuration.USE_DISK), type, bundle.getString(Configuration.USE_DISK+DESC), ModelType.BOOLEAN, false, "true"); //$NON-NLS-1$
+ addAttribute(node, BS(Configuration.PROCESSOR_BATCH_SIZE), type, bundle.getString(Configuration.PROCESSOR_BATCH_SIZE+DESC), ModelType.INT, false, "512"); //$NON-NLS-1$
+ addAttribute(node, BS(Configuration.CONNECTOR_BATCH_SIZE), type, bundle.getString(Configuration.CONNECTOR_BATCH_SIZE+DESC), ModelType.INT, false, "1024"); //$NON-NLS-1$
+ addAttribute(node, BS(Configuration.MAX_PROCESSING_KB), type, bundle.getString(Configuration.MAX_PROCESSING_KB+DESC), ModelType.INT, false, "-1"); //$NON-NLS-1$
+ addAttribute(node, BS(Configuration.MAX_RESERVED_KB), type, bundle.getString(Configuration.MAX_RESERVED_KB+DESC), ModelType.INT, false, "-1"); //$NON-NLS-1$
+ addAttribute(node, BS(Configuration.MAX_FILE_SIZE), type, bundle.getString(Configuration.MAX_FILE_SIZE+DESC), ModelType.LONG, false, "2048"); //$NON-NLS-1$
+ addAttribute(node, BS(Configuration.MAX_BUFFER_SPACE), type, bundle.getString(Configuration.MAX_BUFFER_SPACE+DESC), ModelType.LONG, false, "51200"); //$NON-NLS-1$
+ addAttribute(node, BS(Configuration.MAX_OPEN_FILES), type, bundle.getString(Configuration.MAX_OPEN_FILES+DESC), ModelType.INT, false, "64"); //$NON-NLS-1$
}
+
+ private static String ORC(String name) {
+ return Configuration.OBJECT_REPLICATOR+DASH+name;
+ }
+ static void describeObjectReplicator(ModelNode node, String type, ResourceBundle bundle) {
+ addAttribute(node, ORC(Configuration.STACK), type, bundle.getString(Configuration.STACK+DESC), ModelType.STRING, false, null);
+ addAttribute(node, ORC(Configuration.CLUSTER_NAME), type, bundle.getString(Configuration.CLUSTER_NAME+DESC), ModelType.STRING, false, null);
+ }
private BufferServiceImpl buildBufferManager(ModelNode node) {
BufferServiceImpl bufferManger = new BufferServiceImpl();
@@ -301,132 +296,125 @@
return bufferManger;
}
- if (node.hasDefined(Configuration.USE_DISK)) {
- bufferManger.setUseDisk(node.get(Configuration.USE_DISK).asBoolean());
+ if (node.hasDefined(BS(Configuration.USE_DISK))) {
+ bufferManger.setUseDisk(node.get(BS(Configuration.USE_DISK)).asBoolean());
}
- if (node.hasDefined(Configuration.PROCESSOR_BATCH_SIZE)) {
- bufferManger.setProcessorBatchSize(node.get(Configuration.PROCESSOR_BATCH_SIZE).asInt());
+ if (node.hasDefined(BS(Configuration.PROCESSOR_BATCH_SIZE))) {
+ bufferManger.setProcessorBatchSize(node.get(BS(Configuration.PROCESSOR_BATCH_SIZE)).asInt());
}
- if (node.hasDefined(Configuration.CONNECTOR_BATCH_SIZE)) {
- bufferManger.setConnectorBatchSize(node.get(Configuration.CONNECTOR_BATCH_SIZE).asInt());
+ if (node.hasDefined(BS(Configuration.CONNECTOR_BATCH_SIZE))) {
+ bufferManger.setConnectorBatchSize(node.get(BS(Configuration.CONNECTOR_BATCH_SIZE)).asInt());
}
- if (node.hasDefined(Configuration.MAX_PROCESSING_KB)) {
- bufferManger.setMaxProcessingKb(node.get(Configuration.MAX_PROCESSING_KB).asInt());
+ if (node.hasDefined(BS(Configuration.MAX_PROCESSING_KB))) {
+ bufferManger.setMaxProcessingKb(node.get(BS(Configuration.MAX_PROCESSING_KB)).asInt());
}
- if (node.hasDefined(Configuration.MAX_RESERVED_KB)) {
- bufferManger.setMaxReserveKb(node.get(Configuration.MAX_RESERVED_KB).asInt());
+ if (node.hasDefined(BS(Configuration.MAX_RESERVED_KB))) {
+ bufferManger.setMaxReserveKb(node.get(BS(Configuration.MAX_RESERVED_KB)).asInt());
}
- if (node.hasDefined(Configuration.MAX_FILE_SIZE)) {
- bufferManger.setMaxFileSize(node.get(Configuration.MAX_FILE_SIZE).asLong());
+ if (node.hasDefined(BS(Configuration.MAX_FILE_SIZE))) {
+ bufferManger.setMaxFileSize(node.get(BS(Configuration.MAX_FILE_SIZE)).asLong());
}
- if (node.hasDefined(Configuration.MAX_BUFFER_SPACE)) {
- bufferManger.setMaxBufferSpace(node.get(Configuration.MAX_BUFFER_SPACE).asLong());
+ if (node.hasDefined(BS(Configuration.MAX_BUFFER_SPACE))) {
+ bufferManger.setMaxBufferSpace(node.get(BS(Configuration.MAX_BUFFER_SPACE)).asLong());
}
- if (node.hasDefined(Configuration.MAX_OPEN_FILES)) {
- bufferManger.setMaxOpenFiles(node.get(Configuration.MAX_OPEN_FILES).asInt());
+ if (node.hasDefined(BS(Configuration.MAX_OPEN_FILES))) {
+ bufferManger.setMaxOpenFiles(node.get(BS(Configuration.MAX_OPEN_FILES)).asInt());
}
return bufferManger;
}
private static void populateBufferManager(ModelNode operation, ModelNode model) {
- ModelNode childNode = operation.get(CHILDREN, Configuration.BUFFER_SERVICE);
- if (!childNode.isDefined()) {
- return;
- }
- if (operation.hasDefined(Configuration.USE_DISK)) {
- model.get(Configuration.USE_DISK).set(operation.get(Configuration.USE_DISK).asString());
+ if (operation.hasDefined(BS(Configuration.USE_DISK))) {
+ model.get(BS(Configuration.USE_DISK)).set(operation.get(BS(Configuration.USE_DISK)).asString());
}
- if (operation.hasDefined(Configuration.PROCESSOR_BATCH_SIZE)) {
- model.get(Configuration.PROCESSOR_BATCH_SIZE).set(operation.get(Configuration.PROCESSOR_BATCH_SIZE).asString());
+ if (operation.hasDefined(BS(Configuration.PROCESSOR_BATCH_SIZE))) {
+ model.get(BS(Configuration.PROCESSOR_BATCH_SIZE)).set(operation.get(BS(Configuration.PROCESSOR_BATCH_SIZE)).asString());
}
- if (operation.hasDefined(Configuration.CONNECTOR_BATCH_SIZE)) {
- model.get(Configuration.CONNECTOR_BATCH_SIZE).set(operation.get(Configuration.CONNECTOR_BATCH_SIZE).asString());
+ if (operation.hasDefined(BS(Configuration.CONNECTOR_BATCH_SIZE))) {
+ model.get(BS(Configuration.CONNECTOR_BATCH_SIZE)).set(operation.get(BS(Configuration.CONNECTOR_BATCH_SIZE)).asString());
}
- if (operation.hasDefined(Configuration.MAX_PROCESSING_KB)) {
- model.get(Configuration.MAX_PROCESSING_KB).set(operation.get(Configuration.MAX_PROCESSING_KB).asString());
+ if (operation.hasDefined(BS(Configuration.MAX_PROCESSING_KB))) {
+ model.get(BS(Configuration.MAX_PROCESSING_KB)).set(operation.get(BS(Configuration.MAX_PROCESSING_KB)).asString());
}
- if (operation.hasDefined(Configuration.MAX_RESERVED_KB)) {
- model.get(Configuration.MAX_RESERVED_KB).set(operation.get(Configuration.MAX_RESERVED_KB).asString());
+ if (operation.hasDefined(BS(Configuration.MAX_RESERVED_KB))) {
+ model.get(BS(Configuration.MAX_RESERVED_KB)).set(operation.get(BS(Configuration.MAX_RESERVED_KB)).asString());
}
- if (operation.hasDefined(Configuration.MAX_FILE_SIZE)) {
- model.get(Configuration.MAX_FILE_SIZE).set(operation.get(Configuration.MAX_FILE_SIZE).asString());
+ if (operation.hasDefined(BS(Configuration.MAX_FILE_SIZE))) {
+ model.get(BS(Configuration.MAX_FILE_SIZE)).set(operation.get(BS(Configuration.MAX_FILE_SIZE)).asString());
}
- if (operation.hasDefined(Configuration.MAX_BUFFER_SPACE)) {
- model.get(Configuration.MAX_BUFFER_SPACE).set(operation.get(Configuration.MAX_BUFFER_SPACE).asString());
+ if (operation.hasDefined(BS(Configuration.MAX_BUFFER_SPACE))) {
+ model.get(BS(Configuration.MAX_BUFFER_SPACE)).set(operation.get(BS(Configuration.MAX_BUFFER_SPACE)).asString());
}
- if (operation.hasDefined(Configuration.MAX_BUFFER_SPACE)) {
- model.get(Configuration.MAX_BUFFER_SPACE).set(operation.get(Configuration.MAX_BUFFER_SPACE).asString());
+ if (operation.hasDefined(BS(Configuration.MAX_BUFFER_SPACE))) {
+ model.get(BS(Configuration.MAX_BUFFER_SPACE)).set(operation.get(BS(Configuration.MAX_BUFFER_SPACE)).asString());
}
- if (operation.hasDefined(Configuration.MAX_OPEN_FILES)) {
- model.get(Configuration.MAX_OPEN_FILES).set(operation.get(Configuration.MAX_OPEN_FILES).asString());
+ if (operation.hasDefined(BS(Configuration.MAX_OPEN_FILES))) {
+ model.get(BS(Configuration.MAX_OPEN_FILES)).set(operation.get(BS(Configuration.MAX_OPEN_FILES)).asString());
}
}
private static void populateResultsetCache(ModelNode operation, ModelNode model) {
- if (operation.hasDefined(Configuration.RESULTSET_CACHE)) {
- ModelNode cache = operation.get(Configuration.RESULTSET_CACHE);
- if (cache.hasDefined(Configuration.NAME)) {
- model.get(Configuration.RESULTSET_CACHE, Configuration.NAME).set(cache.get(Configuration.NAME).asString());
- }
-
- if (cache.hasDefined(Configuration.CONTAINER_NAME)) {
- model.get(Configuration.RESULTSET_CACHE, Configuration.CONTAINER_NAME).set(cache.get(Configuration.CONTAINER_NAME).asString());
- }
+ if (operation.hasDefined(RSC(Configuration.NAME))) {
+ model.get(RSC(Configuration.NAME)).set(operation.get(RSC(Configuration.NAME)).asString());
+ }
+
+ if (operation.hasDefined(RSC(Configuration.CONTAINER_NAME))) {
+ model.get(RSC(Configuration.CONTAINER_NAME)).set(operation.get(RSC(Configuration.CONTAINER_NAME)).asString());
+ }
- if (cache.hasDefined(Configuration.ENABLE)) {
- model.get(Configuration.RESULTSET_CACHE, Configuration.ENABLE).set(cache.get(Configuration.ENABLE).asBoolean());
- }
+ if (operation.hasDefined(RSC(Configuration.ENABLE))) {
+ model.get(RSC(Configuration.ENABLE)).set(operation.get(RSC(Configuration.ENABLE)).asBoolean());
+ }
- if (cache.hasDefined(Configuration.MAX_STALENESS)) {
- model.get(Configuration.RESULTSET_CACHE, Configuration.MAX_STALENESS).set(cache.get(Configuration.MAX_STALENESS).asInt());
- }
+ if (operation.hasDefined(RSC(Configuration.MAX_STALENESS))) {
+ model.get(RSC(Configuration.MAX_STALENESS)).set(operation.get(RSC(Configuration.MAX_STALENESS)).asInt());
}
}
private static void populateObjectReplicator(ModelNode operation, ModelNode model) {
- if (operation.hasDefined(Configuration.OBJECT_REPLICATOR)) {
- ModelNode replicator = operation.get(Configuration.OBJECT_REPLICATOR);
- if (replicator.hasDefined(Configuration.STACK)) {
- model.get(Configuration.OBJECT_REPLICATOR, Configuration.STACK).set(replicator.get(Configuration.STACK).asString());
- }
-
- if (replicator.hasDefined(Configuration.CLUSTER_NAME)) {
- model.get(Configuration.OBJECT_REPLICATOR, Configuration.CLUSTER_NAME).set(replicator.get(Configuration.CLUSTER_NAME).asString());
- }
+ if (operation.hasDefined(ORC(Configuration.STACK))) {
+ model.get(ORC(Configuration.STACK)).set(operation.get(ORC(Configuration.STACK)).asString());
}
+
+ if (operation.hasDefined(ORC(Configuration.CLUSTER_NAME))) {
+ model.get(ORC(Configuration.CLUSTER_NAME)).set(operation.get(ORC(Configuration.CLUSTER_NAME)).asString());
+ }
}
private static void populatePreparedPlanCache(ModelNode operation, ModelNode model) {
- if (operation.hasDefined(Configuration.PREPAREDPLAN_CACHE)) {
- ModelNode cache = operation.get(Configuration.PREPAREDPLAN_CACHE);
- if (cache.hasDefined(Configuration.MAX_ENTRIES)) {
- model.get(Configuration.MAX_ENTRIES).set(cache.get(Configuration.MAX_ENTRIES).asInt());
- }
- if (cache.hasDefined(Configuration.MAX_AGE_IN_SECS)) {
- model.get(Configuration.MAX_AGE_IN_SECS).set(cache.get(Configuration.MAX_AGE_IN_SECS).asInt());
- }
- if (cache.hasDefined(Configuration.MAX_STALENESS)) {
- model.get(Configuration.MAX_STALENESS).set(cache.get(Configuration.MAX_STALENESS).asInt());
- }
- }
+ if (operation.hasDefined(PPC(Configuration.MAX_ENTRIES))) {
+ model.get(PPC(Configuration.MAX_ENTRIES)).set(operation.get(PPC(Configuration.MAX_ENTRIES)).asInt());
+ }
+ if (operation.hasDefined(PPC(Configuration.MAX_AGE_IN_SECS))) {
+ model.get(PPC(Configuration.MAX_AGE_IN_SECS)).set(operation.get(PPC(Configuration.MAX_AGE_IN_SECS)).asInt());
+ }
+ if (operation.hasDefined(PPC(Configuration.MAX_STALENESS))) {
+ model.get(PPC(Configuration.MAX_STALENESS)).set(operation.get(PPC(Configuration.MAX_STALENESS)).asInt());
+ }
}
+ private static String RSC(String name) {
+ return Configuration.RESULTSET_CACHE+DASH+name;
+ }
private static void describeResultsetCache(ModelNode node, String type, ResourceBundle bundle) {
- addAttribute(node, Configuration.NAME, type, bundle.getString(Configuration.NAME+DESC), ModelType.STRING, false, "resultset"); //$NON-NLS-1$
- addAttribute(node, Configuration.MAX_STALENESS, type, bundle.getString(Configuration.MAX_STALENESS+DESC), ModelType.INT, false, "60");//$NON-NLS-1$
- addAttribute(node, Configuration.ENABLE, type, bundle.getString(Configuration.ENABLE+DESC), ModelType.BOOLEAN, false, null);
- addAttribute(node, Configuration.CONTAINER_NAME, type, bundle.getString(Configuration.CONTAINER_NAME+DESC), ModelType.STRING, false, null);
+ addAttribute(node, RSC(Configuration.NAME), type, bundle.getString(RSC(Configuration.NAME)+DESC), ModelType.STRING, false, "resultset"); //$NON-NLS-1$
+ addAttribute(node, RSC(Configuration.MAX_STALENESS), type, bundle.getString(Configuration.MAX_STALENESS+DESC), ModelType.INT, false, "60");//$NON-NLS-1$
+ addAttribute(node, RSC(Configuration.ENABLE), type, bundle.getString(Configuration.ENABLE+DESC), ModelType.BOOLEAN, false, null);
+ addAttribute(node, RSC(Configuration.CONTAINER_NAME), type, bundle.getString(Configuration.CONTAINER_NAME+DESC), ModelType.STRING, false, null);
}
+ private static String PPC(String name) {
+ return Configuration.PREPAREDPLAN_CACHE+DASH+name;
+ }
private static void describePreparedPlanCache(ModelNode node, String type, ResourceBundle bundle) {
- addAttribute(node, Configuration.MAX_ENTRIES, type, bundle.getString(Configuration.MAX_ENTRIES+DESC), ModelType.INT, false, "512"); //$NON-NLS-1$
- addAttribute(node, Configuration.MAX_AGE_IN_SECS, type, bundle.getString(Configuration.MAX_AGE_IN_SECS+DESC), ModelType.INT, false, "28800");//$NON-NLS-1$
- addAttribute(node, Configuration.MAX_STALENESS, type, bundle.getString(Configuration.MAX_STALENESS+DESC), ModelType.INT, false, "0");//$NON-NLS-1$
+ addAttribute(node, PPC(Configuration.MAX_ENTRIES), type, bundle.getString(Configuration.MAX_ENTRIES+DESC), ModelType.INT, false, "512"); //$NON-NLS-1$
+ addAttribute(node, PPC(Configuration.MAX_AGE_IN_SECS), type, bundle.getString(Configuration.MAX_AGE_IN_SECS+DESC), ModelType.INT, false, "28800");//$NON-NLS-1$
+ addAttribute(node, PPC(Configuration.MAX_STALENESS), type, bundle.getString(Configuration.MAX_STALENESS+DESC), ModelType.INT, false, "0");//$NON-NLS-1$
}
- private SessionAwareCache<CachedResults> buildResultsetCache(ModelNode operation, BufferManager bufferManager) throws OperationFailedException {
+ private SessionAwareCache<CachedResults> buildResultsetCache(ModelNode operation, BufferManager bufferManager) {
CacheConfiguration cacheConfig = new CacheConfiguration();
// these settings are not really used; they are defined by infinispan
@@ -436,37 +424,33 @@
cacheConfig.setLocation("resultset"); //$NON-NLS-1$
cacheConfig.setMaxStaleness(60);
- if (!operation.hasDefined(Configuration.RESULTSET_CACHE)) {
- SessionAwareCache<CachedResults> resultsetCache = new SessionAwareCache<CachedResults>(new DefaultCacheFactory(), SessionAwareCache.Type.RESULTSET, cacheConfig);
- resultsetCache.setBufferManager(bufferManager);
- return resultsetCache;
- }
+ if (operation.hasDefined(RSC(Configuration.ENABLE))) {
+ if (!operation.get(RSC(Configuration.ENABLE)).asBoolean()) {
+ return null;
+ }
+ }
- ModelNode node = operation.get(Configuration.RESULTSET_CACHE);
- ClusterableCacheFactory cacheFactory = new ClusterableCacheFactory();
+ ClusterableCacheFactory cacheFactory = null;
- if (node.hasDefined(Configuration.CONTAINER_NAME)) {
- cacheFactory.setCacheManager(node.get(Configuration.CONTAINER_NAME).asString());
+ if (operation.hasDefined(RSC(Configuration.CONTAINER_NAME))) {
+ cacheFactory = new ClusterableCacheFactory();
+ cacheFactory.setCacheManager(operation.get(RSC(Configuration.CONTAINER_NAME)).asString());
}
else {
- throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString("cache-container-name-required"))); //$NON-NLS-1$
+ SessionAwareCache<CachedResults> resultsetCache = new SessionAwareCache<CachedResults>(new DefaultCacheFactory(), SessionAwareCache.Type.RESULTSET, cacheConfig);
+ resultsetCache.setBufferManager(bufferManager);
+ return resultsetCache;
}
- if (node.hasDefined(Configuration.NAME)) {
- cacheFactory.setResultsetCacheName(node.get(Configuration.NAME).asString());
+ if (operation.hasDefined(RSC(Configuration.NAME))) {
+ cacheFactory.setResultsetCacheName(operation.get(RSC(Configuration.NAME)).asString());
}
else {
cacheFactory.setResultsetCacheName("resultset"); //$NON-NLS-1$
}
-
- if (node.hasDefined(Configuration.ENABLE)) {
- if (!node.get(Configuration.ENABLE).asBoolean()) {
- return null;
- }
- }
- if (node.hasDefined(Configuration.MAX_STALENESS)) {
- cacheConfig.setMaxStaleness(node.get(Configuration.MAX_STALENESS).asInt());
+ if (operation.hasDefined(RSC(Configuration.MAX_STALENESS))) {
+ cacheConfig.setMaxStaleness(operation.get(RSC(Configuration.MAX_STALENESS)).asInt());
}
SessionAwareCache<CachedResults> resultsetCache = new SessionAwareCache<CachedResults>(cacheFactory, SessionAwareCache.Type.RESULTSET, cacheConfig);
@@ -477,22 +461,22 @@
private SessionAwareCache<PreparedPlan> buildPreparedPlanCache(ModelNode node, BufferManager bufferManager) {
CacheConfiguration cacheConfig = new CacheConfiguration();
- if (node.hasDefined(Configuration.MAX_ENTRIES)) {
- cacheConfig.setMaxEntries(node.get(Configuration.MAX_ENTRIES).asInt());
+ if (node.hasDefined(PPC(Configuration.MAX_ENTRIES))) {
+ cacheConfig.setMaxEntries(node.get(PPC(Configuration.MAX_ENTRIES)).asInt());
}
else {
cacheConfig.setMaxEntries(512);
}
- if (node.hasDefined(Configuration.MAX_AGE_IN_SECS)) {
- cacheConfig.setMaxAgeInSeconds(node.get(Configuration.MAX_AGE_IN_SECS).asInt());
+ if (node.hasDefined(PPC(Configuration.MAX_AGE_IN_SECS))) {
+ cacheConfig.setMaxAgeInSeconds(node.get(PPC(Configuration.MAX_AGE_IN_SECS)).asInt());
}
else {
cacheConfig.setMaxAgeInSeconds(28800);
}
- if (node.hasDefined(Configuration.MAX_STALENESS)) {
- cacheConfig.setMaxStaleness(node.get(Configuration.MAX_STALENESS).asInt());
+ if (node.hasDefined(PPC(Configuration.MAX_STALENESS))) {
+ cacheConfig.setMaxStaleness(node.get(PPC(Configuration.MAX_STALENESS)).asInt());
}
else {
cacheConfig.setMaxStaleness(0);
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidExtension.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidExtension.java 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidExtension.java 2011-09-28 15:25:16 UTC (rev 3505)
@@ -119,8 +119,12 @@
new AddDataRole().register(teiidSubsystem);
new RemoveDataRole().register(teiidSubsystem);
new AddAnyAuthenticatedDataRole().register(teiidSubsystem);
+ new AssignDataSource().register(teiidSubsystem);
+ new ChangeVDBConnectionType().register(teiidSubsystem);
+ new RemoveAnyAuthenticatedDataRole().register(teiidSubsystem);
// engine level admin api handlers
+ new ListRequests().register(engineSubsystem);
new ListSessions().register(engineSubsystem);
new RequestsPerSession().register(engineSubsystem);
new RequestsPerVDB().register(engineSubsystem);
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidSubsystemDescribe.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidSubsystemDescribe.java 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidSubsystemDescribe.java 2011-09-28 15:25:16 UTC (rev 3505)
@@ -81,7 +81,7 @@
addOperation.get(OP).set(ADD);
addOperation.get(OP_ADDR).set(address);
- QueryEngineAdd.populate(container.getName(), container.getValue(), addOperation);
+ QueryEngineAdd.populate(container.getValue(), addOperation);
result.add(addOperation);
}
@@ -96,7 +96,7 @@
addOperation.get(OP).set(ADD);
addOperation.get(OP_ADDR).set(address);
- TranslatorAdd.populate(container.getName(), container.getValue(), addOperation);
+ TranslatorAdd.populate(container.getValue(), addOperation);
result.add(addOperation);
}
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidSubsystemParser.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidSubsystemParser.java 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidSubsystemParser.java 2011-09-28 15:25:16 UTC (rev 3505)
@@ -27,6 +27,8 @@
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
import static org.jboss.as.controller.parsing.ParseUtils.requireNoAttributes;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -51,68 +53,76 @@
return;
}
+ writeElement(writer, Element.ALLOW_ENV_FUNCTION_ELEMENT, node);
writeElement(writer, Element.ASYNC_THREAD_GROUP_ELEMENT, node);
- writeElement(writer, Element.ALLOW_ENV_FUNCTION_ELEMENT, node);
- writeElement(writer, Element.AUTHORIZATION_VALIDATOR_MODULE_ELEMENT, node);
- writeElement(writer, Element.POLICY_DECIDER_MODULE_ELEMENT, node);
- if (has(node, Element.BUFFER_SERVICE_ELEMENT.getLocalName())){
+ if (like(node, Element.BUFFER_SERVICE_ELEMENT)){
writer.writeStartElement(Element.BUFFER_SERVICE_ELEMENT.getLocalName());
- writeBufferService(writer, node.get(Element.BUFFER_SERVICE_ELEMENT.getLocalName()));
+ writeBufferService(writer, node);
writer.writeEndElement();
}
+
+ writeElement(writer, Element.AUTHORIZATION_VALIDATOR_MODULE_ELEMENT, node);
+ writeElement(writer, Element.POLICY_DECIDER_MODULE_ELEMENT, node);
+
- if (has(node, Element.RESULTSET_CACHE_ELEMENT.getLocalName())){
+ if (like(node, Element.RESULTSET_CACHE_ELEMENT)){
writer.writeStartElement(Element.RESULTSET_CACHE_ELEMENT.getLocalName());
- writeResultsetCacheConfiguration(writer, node.get(Element.RESULTSET_CACHE_ELEMENT.getLocalName()));
+ writeResultsetCacheConfiguration(writer, node);
writer.writeEndElement();
}
- if (has(node, Element.PREPAREDPLAN_CACHE_ELEMENT.getLocalName())){
+ if (like(node, Element.PREPAREDPLAN_CACHE_ELEMENT)){
writer.writeStartElement(Element.PREPAREDPLAN_CACHE_ELEMENT.getLocalName());
- writePreparedPlanCacheConfiguration(writer, node.get(Element.PREPAREDPLAN_CACHE_ELEMENT.getLocalName()));
+ writePreparedPlanCacheConfiguration(writer, node);
writer.writeEndElement();
}
- if (has(node, Element.OBJECT_REPLICATOR_ELEMENT.getLocalName())){
+ if (like(node, Element.OBJECT_REPLICATOR_ELEMENT)){
writer.writeStartElement(Element.OBJECT_REPLICATOR_ELEMENT.getLocalName());
- writeObjectReplicatorConfiguration(writer, node.get(Element.OBJECT_REPLICATOR_ELEMENT.getLocalName()));
+ writeObjectReplicatorConfiguration(writer, node);
writer.writeEndElement();
}
- Set<String> engines = node.get(Element.QUERY_ENGINE_ELEMENT.getLocalName()).keys();
- if (engines != null && !engines.isEmpty()) {
- for (String engine:engines) {
- writer.writeStartElement(Element.QUERY_ENGINE_ELEMENT.getLocalName());
- writeQueryEngine(writer, node.get(Element.QUERY_ENGINE_ELEMENT.getLocalName(), engine));
- writer.writeEndElement();
- }
+ if (has(node, Element.QUERY_ENGINE_ELEMENT.getLocalName())) {
+ ArrayList<String> engines = new ArrayList<String>(node.get(Element.QUERY_ENGINE_ELEMENT.getLocalName()).keys());
+ Collections.sort(engines);
+ if (!engines.isEmpty()) {
+ for (String engine:engines) {
+ writer.writeStartElement(Element.QUERY_ENGINE_ELEMENT.getLocalName());
+ writeQueryEngine(writer, node.get(Element.QUERY_ENGINE_ELEMENT.getLocalName(), engine), engine);
+ writer.writeEndElement();
+ }
+ }
}
- Set<String> translators = node.get(Element.TRANSLATOR_ELEMENT.getLocalName()).keys();
- if (translators != null && !translators.isEmpty()) {
- for (String translator:translators) {
- writer.writeStartElement(Element.TRANSLATOR_ELEMENT.getLocalName());
- writeTranslator(writer, node.get(Element.TRANSLATOR_ELEMENT.getLocalName(), translator));
- writer.writeEndElement();
- }
- }
+ if (has(node, Element.TRANSLATOR_ELEMENT.getLocalName())) {
+ ArrayList<String> translators = new ArrayList<String>(node.get(Element.TRANSLATOR_ELEMENT.getLocalName()).keys());
+ Collections.sort(translators);
+ if (!translators.isEmpty()) {
+ for (String translator:translators) {
+ writer.writeStartElement(Element.TRANSLATOR_ELEMENT.getLocalName());
+ writeTranslator(writer, node.get(Element.TRANSLATOR_ELEMENT.getLocalName(), translator), translator);
+ writer.writeEndElement();
+ }
+ }
+ }
writer.writeEndElement(); // End of subsystem element
}
private void writeObjectReplicatorConfiguration(XMLExtendedStreamWriter writer, ModelNode node) throws XMLStreamException {
- writeAttribute(writer, Element.STACK_ATTRIBUTE, node);
- writeAttribute(writer, Element.CLUSTER_NAME_ATTRIBUTE, node);
+ writeAttribute(writer, Element.OR_STACK_ATTRIBUTE, node);
+ writeAttribute(writer, Element.OR_CLUSTER_NAME_ATTRIBUTE, node);
}
- private void writeTranslator(XMLExtendedStreamWriter writer, ModelNode node) throws XMLStreamException {
- writeAttribute(writer, Element.TRANSLATOR_NAME_ATTRIBUTE, node);
+ private void writeTranslator(XMLExtendedStreamWriter writer, ModelNode node, String translatorName) throws XMLStreamException {
+ writer.writeAttribute(Element.TRANSLATOR_NAME_ATTRIBUTE.getLocalName(), translatorName);
writeAttribute(writer, Element.TRANSLATOR_MODULE_ATTRIBUTE, node);
}
// write the elements according to the schema defined.
- private void writeQueryEngine( XMLExtendedStreamWriter writer, ModelNode node) throws XMLStreamException {
- writeAttribute(writer, Element.ENGINE_NAME_ATTRIBUTE, node);
+ private void writeQueryEngine( XMLExtendedStreamWriter writer, ModelNode node, String engineName) throws XMLStreamException {
+ writer.writeAttribute(Element.ENGINE_NAME_ATTRIBUTE.getLocalName(), engineName);
writeElement(writer, Element.MAX_THREADS_ELEMENT, node);
writeElement(writer, Element.MAX_ACTIVE_PLANS_ELEMENT, node);
@@ -139,45 +149,72 @@
//jdbc
- if (has(node, Element.JDBC_ELEMENT.getLocalName())){
- writer.writeStartElement(Element.JDBC_ELEMENT.getLocalName());
- writeSocketConfiguration(writer, node.get(Element.JDBC_ELEMENT.getLocalName()));
- writer.writeEndElement();
+ if (like(node, Element.JDBC_ELEMENT)) {
+ writer.writeStartElement(Element.JDBC_ELEMENT.getLocalName());
+ writeJDBCSocketConfiguration(writer, node);
+ writer.writeEndElement();
}
//odbc
- if (has(node, Element.ODBC_ELEMENT.getLocalName())) {
- writer.writeStartElement(Element.ODBC_ELEMENT.getLocalName());
- writeSocketConfiguration(writer, node.get(Element.ODBC_ELEMENT.getLocalName()));
- writer.writeEndElement();
+ if (like(node, Element.ODBC_ELEMENT)) {
+ writer.writeStartElement(Element.ODBC_ELEMENT.getLocalName());
+ writeODBCSocketConfiguration(writer, node);
+ writer.writeEndElement();
}
}
- private void writeSocketConfiguration(XMLExtendedStreamWriter writer, ModelNode node) throws XMLStreamException {
- writeAttribute(writer, Element.SOCKET_BINDING_ELEMENT, node);
- writeElement(writer, Element.MAX_SOCKET_THREAD_SIZE_ELEMENT, node);
- writeElement(writer, Element.IN_BUFFER_SIZE_ELEMENT, node);
- writeElement(writer, Element.OUT_BUFFER_SIZE_ELEMENT, node);
-
- if (has(node, Element.SSL_ELEMENT.getLocalName())) {
- writer.writeStartElement(Element.SSL_ELEMENT.getLocalName());
- writeSSLConfiguration(writer, node.get(Element.SSL_ELEMENT.getLocalName()));
- writer.writeEndElement();
+ private void writeJDBCSocketConfiguration(XMLExtendedStreamWriter writer, ModelNode node) throws XMLStreamException {
+ writeAttribute(writer, Element.JDBC_SOCKET_BINDING_ATTRIBUTE, node);
+ writeAttribute(writer, Element.JDBC_MAX_SOCKET_THREAD_SIZE_ATTRIBUTE, node);
+ writeAttribute(writer, Element.JDBC_IN_BUFFER_SIZE_ATTRIBUTE, node);
+ writeAttribute(writer, Element.JDBC_OUT_BUFFER_SIZE_ATTRIBUTE, node);
+
+ // SSL
+ if (like(node, Element.JDBC_SSL_ELEMENT)) {
+ writer.writeStartElement(Element.JDBC_SSL_ELEMENT.getLocalName());
+ writeJDBCSSLConfiguration(writer, node);
+ writer.writeEndElement();
}
}
- private void writeSSLConfiguration(XMLExtendedStreamWriter writer, ModelNode node) throws XMLStreamException {
- writeElement(writer, Element.SSL_MODE_ELEMENT, node);
- writeElement(writer, Element.KEY_STORE_FILE_ELEMENT, node);
- writeElement(writer, Element.KEY_STORE_PASSWD_ELEMENT, node);
- writeElement(writer, Element.KEY_STORE_TYPE_ELEMENT, node);
- writeElement(writer, Element.SSL_PROTOCOL_ELEMENT, node);
- writeElement(writer, Element.TRUST_FILE_ELEMENT, node);
- writeElement(writer, Element.TRUST_PASSWD_ELEMENT, node);
- writeElement(writer, Element.AUTH_MODE_ELEMENT, node);
- writeElement(writer, Element.KEY_MANAGEMENT_ALG_ELEMENT, node);
+ private void writeJDBCSSLConfiguration(XMLExtendedStreamWriter writer, ModelNode node) throws XMLStreamException {
+ writeElement(writer, Element.JDBC_SSL_MODE_ELEMENT, node);
+ writeElement(writer, Element.JDBC_AUTH_MODE_ELEMENT, node);
+ writeElement(writer, Element.JDBC_SSL_PROTOCOL_ELEMENT, node);
+ writeElement(writer, Element.JDBC_KEY_MANAGEMENT_ALG_ELEMENT, node);
+ writeElement(writer, Element.JDBC_KEY_STORE_FILE_ELEMENT, node);
+ writeElement(writer, Element.JDBC_KEY_STORE_PASSWD_ELEMENT, node);
+ writeElement(writer, Element.JDBC_KEY_STORE_TYPE_ELEMENT, node);
+ writeElement(writer, Element.JDBC_TRUST_FILE_ELEMENT, node);
+ writeElement(writer, Element.JDBC_TRUST_PASSWD_ELEMENT, node);
}
+
+ private void writeODBCSocketConfiguration(XMLExtendedStreamWriter writer, ModelNode node) throws XMLStreamException {
+ writeAttribute(writer, Element.ODBC_SOCKET_BINDING_ATTRIBUTE, node);
+ writeAttribute(writer, Element.ODBC_MAX_SOCKET_THREAD_SIZE_ATTRIBUTE, node);
+ writeAttribute(writer, Element.ODBC_IN_BUFFER_SIZE_ATTRIBUTE, node);
+ writeAttribute(writer, Element.ODBC_OUT_BUFFER_SIZE_ATTRIBUTE, node);
+ // SSL
+ if (like(node, Element.ODBC_SSL_ELEMENT)) {
+ writer.writeStartElement(Element.ODBC_SSL_ELEMENT.getLocalName());
+ writeODBCSSLConfiguration(writer, node);
+ writer.writeEndElement();
+ }
+ }
+
+ private void writeODBCSSLConfiguration(XMLExtendedStreamWriter writer, ModelNode node) throws XMLStreamException {
+ writeElement(writer, Element.ODBC_SSL_MODE_ELEMENT, node);
+ writeElement(writer, Element.ODBC_AUTH_MODE_ELEMENT, node);
+ writeElement(writer, Element.ODBC_SSL_PROTOCOL_ELEMENT, node);
+ writeElement(writer, Element.ODBC_KEY_MANAGEMENT_ALG_ELEMENT, node);
+ writeElement(writer, Element.ODBC_KEY_STORE_FILE_ELEMENT, node);
+ writeElement(writer, Element.ODBC_KEY_STORE_PASSWD_ELEMENT, node);
+ writeElement(writer, Element.ODBC_KEY_STORE_TYPE_ELEMENT, node);
+ writeElement(writer, Element.ODBC_TRUST_FILE_ELEMENT, node);
+ writeElement(writer, Element.ODBC_TRUST_PASSWD_ELEMENT, node);
+ }
+
private void writeBufferService(XMLExtendedStreamWriter writer, ModelNode node) throws XMLStreamException {
writeElement(writer, Element.USE_DISK_ELEMENT, node);
writeElement(writer, Element.PROCESSOR_BATCH_SIZE_ELEMENT, node);
@@ -190,26 +227,38 @@
}
private void writeResultsetCacheConfiguration(XMLExtendedStreamWriter writer, ModelNode node) throws XMLStreamException {
- writeAttribute(writer, Element.NAME_ELEMENT, node);
- writeAttribute(writer, Element.CONTAINER_NAME_ELEMENT, node);
- writeAttribute(writer, Element.ENABLE_ATTRIBUTE, node);
- writeAttribute(writer, Element.MAX_STALENESS_ELEMENT, node);
+ writeAttribute(writer, Element.RSC_NAME_ELEMENT, node);
+ writeAttribute(writer, Element.RSC_CONTAINER_NAME_ELEMENT, node);
+ writeAttribute(writer, Element.RSC_ENABLE_ATTRIBUTE, node);
+ writeAttribute(writer, Element.RSC_MAX_STALENESS_ELEMENT, node);
}
private void writePreparedPlanCacheConfiguration(XMLExtendedStreamWriter writer, ModelNode node) throws XMLStreamException {
- writeAttribute(writer, Element.MAX_ENTRIES_ELEMENT, node);
- writeAttribute(writer, Element.MAX_AGE_IN_SECS_ELEMENT, node);
- writeAttribute(writer, Element.MAX_STALENESS_ELEMENT, node);
+ writeAttribute(writer, Element.PPC_MAX_ENTRIES_ATTRIBUTE, node);
+ writeAttribute(writer, Element.PPC_MAX_AGE_IN_SECS_ATTRIBUTE, node);
+ writeAttribute(writer, Element.PPC_MAX_STALENESS_ATTRIBUTE, node);
}
private boolean has(ModelNode node, String name) {
return node.has(name) && node.get(name).isDefined();
}
+
+ private boolean like(ModelNode node, Element element) {
+ if (node.isDefined()) {
+ Set<String> keys = node.keys();
+ for (String key:keys) {
+ if (key.startsWith(element.getModelName())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
private void writeElement(final XMLExtendedStreamWriter writer, final Element element, final ModelNode node) throws XMLStreamException {
- if (has(node, element.getLocalName())) {
+ if (has(node, element.getModelName())) {
writer.writeStartElement(element.getLocalName());
- writer.writeCharacters(node.get(element.getLocalName()).asString());
+ writer.writeCharacters(node.get(element.getModelName()).asString());
writer.writeEndElement();
}
}
@@ -223,8 +272,8 @@
}
private void writeAttribute(final XMLExtendedStreamWriter writer, final Element element, final ModelNode node) throws XMLStreamException {
- if (has(node, element.getLocalName())) {
- writer.writeAttribute(element.getLocalName(), node.get(element.getLocalName()).asString());
+ if (has(node, element.getModelName())) {
+ writer.writeAttribute(element.getLocalName(), node.get(element.getModelName()).asString());
}
}
@@ -257,27 +306,29 @@
case ASYNC_THREAD_GROUP_ELEMENT:
bootServices.get(reader.getLocalName()).set(reader.getElementText());
break;
-
+
+ // complex types
case OBJECT_REPLICATOR_ELEMENT:
- bootServices.get(reader.getLocalName()).set(parseObjectReplicator(reader));
+ parseObjectReplicator(reader, bootServices);
break;
- // complex types
case BUFFER_SERVICE_ELEMENT:
- bootServices.get(reader.getLocalName()).set(parseBufferConfiguration(reader));
+ parseBufferConfiguration(reader, bootServices);
break;
case PREPAREDPLAN_CACHE_ELEMENT:
- bootServices.get(reader.getLocalName()).set(parsePreparedPlanCacheConfiguration(reader));
+ parsePreparedPlanCacheConfiguration(reader, bootServices);
break;
case RESULTSET_CACHE_ELEMENT:
- bootServices.get(reader.getLocalName()).set(parseResultsetCacheConfiguration(reader));
+ parseResultsetCacheConfiguration(reader, bootServices);
break;
case QUERY_ENGINE_ELEMENT:
- ModelNode engineNode = parseQueryEngine(reader, new ModelNode());
+ ModelNode engineNode = new ModelNode();
+ String name = parseQueryEngine(reader, engineNode);
+
final ModelNode engineAddress = address.clone();
- engineAddress.add(Configuration.QUERY_ENGINE, engineNode.require(Configuration.ENGINE_NAME).asString());
+ engineAddress.add(Configuration.QUERY_ENGINE, name);
engineAddress.protect();
engineNode.get(OP).set(ADD);
engineNode.get(OP_ADDR).set(engineAddress);
@@ -286,10 +337,12 @@
break;
case TRANSLATOR_ELEMENT:
- ModelNode translatorNode = parseTranslator(reader, new ModelNode());
+ ModelNode translatorNode = new ModelNode();
+
+ String translatorName = parseTranslator(reader, translatorNode);
final ModelNode translatorAddress = address.clone();
- translatorAddress.add(Configuration.TRANSLATOR, translatorNode.require(Configuration.TRANSLATOR_NAME).asString());
+ translatorAddress.add(Configuration.TRANSLATOR, translatorName);
translatorAddress.protect();
translatorNode.get(OP).set(ADD);
@@ -310,26 +363,42 @@
}
}
- private ModelNode parseObjectReplicator(XMLExtendedStreamReader reader) throws XMLStreamException {
- ModelNode node = new ModelNode();
+ private ModelNode parseObjectReplicator(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException {
if (reader.getAttributeCount() > 0) {
for(int i=0; i<reader.getAttributeCount(); i++) {
String attrName = reader.getAttributeLocalName(i);
String attrValue = reader.getAttributeValue(i);
- node.get(attrName).set(attrValue);
+
+ Element element = Element.forName(attrName, Configuration.OBJECT_REPLICATOR);
+ switch(element) {
+ case OR_STACK_ATTRIBUTE:
+ node.get(Element.OR_STACK_ATTRIBUTE.getModelName()).set(attrValue);
+ break;
+ case OR_CLUSTER_NAME_ATTRIBUTE:
+ node.get(Element.OR_CLUSTER_NAME_ATTRIBUTE.getModelName()).set(attrValue);
+ break;
+ default:
+ throw ParseUtils.unexpectedElement(reader);
+ }
}
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT));
return node;
}
- private ModelNode parseQueryEngine(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException {
+ private String parseQueryEngine(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException {
+ String engineName = "default"; //$NON-NLS-1$
if (reader.getAttributeCount() > 0) {
for(int i=0; i<reader.getAttributeCount(); i++) {
String attrName = reader.getAttributeLocalName(i);
String attrValue = reader.getAttributeValue(i);
- node.get(attrName).set(attrValue);
+ if (attrName.equals(Element.ENGINE_NAME_ATTRIBUTE.getLocalName())) {
+ engineName = attrValue;
+ }
+ else {
+ node.get(attrName).set(attrValue);
+ }
}
}
@@ -363,38 +432,47 @@
break;
case JDBC_ELEMENT:
- node.get(reader.getLocalName()).set(parseSocketConfiguration(reader));
+ parseJDBCSocketConfiguration(reader, node);
break;
case ODBC_ELEMENT:
- node.get(reader.getLocalName()).set(parseSocketConfiguration(reader));
+ parseODBCSocketConfiguration(reader, node);
break;
default:
throw ParseUtils.unexpectedElement(reader);
}
}
- return node;
+ return engineName;
}
- private ModelNode parseBufferConfiguration(XMLExtendedStreamReader reader) throws XMLStreamException {
- ModelNode node = new ModelNode();
+ private ModelNode parseBufferConfiguration(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException {
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
- Element element = Element.forName(reader.getLocalName());
+ Element element = Element.forName(reader.getLocalName(), Configuration.BUFFER_SERVICE);
switch (element) {
case USE_DISK_ELEMENT:
- node.get(reader.getLocalName()).set(Boolean.parseBoolean(reader.getElementText()));
+ node.get(Element.USE_DISK_ELEMENT.getModelName()).set(Boolean.parseBoolean(reader.getElementText()));
break;
case PROCESSOR_BATCH_SIZE_ELEMENT:
+ node.get(Element.PROCESSOR_BATCH_SIZE_ELEMENT.getModelName()).set(Integer.parseInt(reader.getElementText()));
+ break;
case CONNECTOR_BATCH_SIZE_ELEMENT:
+ node.get(Element.CONNECTOR_BATCH_SIZE_ELEMENT.getModelName()).set(Integer.parseInt(reader.getElementText()));
+ break;
case MAX_PROCESSING_KB_ELEMENT:
+ node.get(Element.MAX_PROCESSING_KB_ELEMENT.getModelName()).set(Integer.parseInt(reader.getElementText()));
+ break;
case MAX_RESERVED_KB_ELEMENT:
+ node.get(Element.MAX_RESERVED_KB_ELEMENT.getModelName()).set(Integer.parseInt(reader.getElementText()));
+ break;
case MAX_OPEN_FILES_ELEMENT:
- node.get(reader.getLocalName()).set(Integer.parseInt(reader.getElementText()));
+ node.get(Element.MAX_OPEN_FILES_ELEMENT.getModelName()).set(Integer.parseInt(reader.getElementText()));
break;
- case MAX_FILE_SIZE_ELEMENT:
+ case MAX_FILE_SIZE_ELEMENT:
+ node.get(Element.MAX_FILE_SIZE_ELEMENT.getModelName()).set(Long.parseLong(reader.getElementText()));
+ break;
case MAX_BUFFER_SPACE_ELEMENT:
- node.get(reader.getLocalName()).set(Long.parseLong(reader.getElementText()));
+ node.get(Element.MAX_BUFFER_SPACE_ELEMENT.getModelName()).set(Long.parseLong(reader.getElementText()));
break;
default:
throw ParseUtils.unexpectedElement(reader);
@@ -403,73 +481,94 @@
return node;
}
- private ModelNode parsePreparedPlanCacheConfiguration(XMLExtendedStreamReader reader) throws XMLStreamException {
- ModelNode node = new ModelNode();
-
+ private ModelNode parsePreparedPlanCacheConfiguration(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException {
if (reader.getAttributeCount() > 0) {
for(int i=0; i<reader.getAttributeCount(); i++) {
String attrName = reader.getAttributeLocalName(i);
String attrValue = reader.getAttributeValue(i);
- node.get(attrName).set(attrValue);
+ Element element = Element.forName(attrName, Configuration.PREPAREDPLAN_CACHE);
+ switch(element) {
+ case PPC_MAX_ENTRIES_ATTRIBUTE:
+ node.get(Element.PPC_MAX_ENTRIES_ATTRIBUTE.getModelName()).set(Integer.parseInt(attrValue));
+ break;
+
+ case PPC_MAX_AGE_IN_SECS_ATTRIBUTE:
+ node.get(Element.PPC_MAX_AGE_IN_SECS_ATTRIBUTE.getModelName()).set(Integer.parseInt(attrValue));
+ break;
+
+ case PPC_MAX_STALENESS_ATTRIBUTE:
+ node.get(Element.PPC_MAX_STALENESS_ATTRIBUTE.getModelName()).set(Integer.parseInt(attrValue));
+ break;
+ default:
+ throw ParseUtils.unexpectedElement(reader);
+ }
}
}
-
- while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
- Element element = Element.forName(reader.getLocalName());
- switch (element) {
- case MAX_ENTRIES_ELEMENT:
- case MAX_AGE_IN_SECS_ELEMENT:
- case MAX_STALENESS_ELEMENT:
- node.get(reader.getLocalName()).set(Integer.parseInt(reader.getElementText()));
- break;
- default:
- throw ParseUtils.unexpectedElement(reader);
- }
- }
+ while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT));
return node;
}
- private ModelNode parseResultsetCacheConfiguration(XMLExtendedStreamReader reader) throws XMLStreamException {
- ModelNode node = new ModelNode();
-
+ private ModelNode parseResultsetCacheConfiguration(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException {
if (reader.getAttributeCount() > 0) {
for(int i=0; i<reader.getAttributeCount(); i++) {
String attrName = reader.getAttributeLocalName(i);
String attrValue = reader.getAttributeValue(i);
- if (attrName.equals(Element.ENABLE_ATTRIBUTE.getLocalName())) {
- node.get(attrName).set(Boolean.parseBoolean(attrValue));
- }
- else {
- node.get(attrName).set(attrValue);
- }
+ Element element = Element.forName(attrName, Configuration.RESULTSET_CACHE);
+ switch(element) {
+ case RSC_CONTAINER_NAME_ELEMENT:
+ node.get(Element.RSC_CONTAINER_NAME_ELEMENT.getModelName()).set(attrValue);
+ break;
+ case RSC_ENABLE_ATTRIBUTE:
+ node.get(Element.RSC_ENABLE_ATTRIBUTE.getModelName()).set(Boolean.parseBoolean(attrValue));
+ break;
+ case RSC_MAX_STALENESS_ELEMENT:
+ node.get(Element.RSC_MAX_STALENESS_ELEMENT.getModelName()).set(Integer.parseInt(attrValue));
+ break;
+ case RSC_NAME_ELEMENT:
+ node.get(Element.RSC_NAME_ELEMENT.getModelName()).set(attrValue);
+ break;
+ default:
+ throw ParseUtils.unexpectedElement(reader);
+ }
}
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT));
return node;
}
- private ModelNode parseSocketConfiguration(XMLExtendedStreamReader reader) throws XMLStreamException {
- ModelNode node = new ModelNode();
+ private ModelNode parseJDBCSocketConfiguration(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException {
if (reader.getAttributeCount() > 0) {
for(int i=0; i<reader.getAttributeCount(); i++) {
String attrName = reader.getAttributeLocalName(i);
String attrValue = reader.getAttributeValue(i);
- node.get(attrName).set(attrValue);
+
+ Element element = Element.forName(attrName, Configuration.JDBC);
+ switch (element) {
+ case JDBC_SOCKET_BINDING_ATTRIBUTE:
+ node.get(Element.JDBC_SOCKET_BINDING_ATTRIBUTE.getModelName()).set(attrValue);
+ break;
+ case JDBC_MAX_SOCKET_THREAD_SIZE_ATTRIBUTE:
+ node.get(Element.JDBC_MAX_SOCKET_THREAD_SIZE_ATTRIBUTE.getModelName()).set(Integer.parseInt(attrValue));
+ break;
+ case JDBC_IN_BUFFER_SIZE_ATTRIBUTE:
+ node.get(Element.JDBC_IN_BUFFER_SIZE_ATTRIBUTE.getModelName()).set(Integer.parseInt(attrValue));
+ break;
+ case JDBC_OUT_BUFFER_SIZE_ATTRIBUTE:
+ node.get(Element.JDBC_OUT_BUFFER_SIZE_ATTRIBUTE.getModelName()).set(Integer.parseInt(attrValue));
+ break;
+ default:
+ throw ParseUtils.unexpectedElement(reader);
+ }
}
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
- Element element = Element.forName(reader.getLocalName());
+ Element element = Element.forName(reader.getLocalName(), Configuration.JDBC);
switch (element) {
- case MAX_SOCKET_THREAD_SIZE_ELEMENT:
- case IN_BUFFER_SIZE_ELEMENT:
- case OUT_BUFFER_SIZE_ELEMENT:
- node.get(reader.getLocalName()).set(Integer.parseInt(reader.getElementText()));
+ case JDBC_SSL_ELEMENT:
+ parseJDBCSSLConfiguration(reader, node);
break;
- case SSL_ELEMENT:
- node.get(reader.getLocalName()).set(parseSSLConfiguration(reader));
- break;
default:
throw ParseUtils.unexpectedElement(reader);
}
@@ -477,31 +576,124 @@
return node;
}
- private ModelNode parseSSLConfiguration(XMLExtendedStreamReader reader) throws XMLStreamException {
- ModelNode node = new ModelNode();
+ private ModelNode parseODBCSocketConfiguration(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException {
+ if (reader.getAttributeCount() > 0) {
+ for(int i=0; i<reader.getAttributeCount(); i++) {
+ String attrName = reader.getAttributeLocalName(i);
+ String attrValue = reader.getAttributeValue(i);
+
+ Element element = Element.forName(attrName, Configuration.ODBC);
+ switch (element) {
+ case ODBC_SOCKET_BINDING_ATTRIBUTE:
+ node.get(Element.ODBC_SOCKET_BINDING_ATTRIBUTE.getModelName()).set(attrValue);
+ break;
+ case ODBC_MAX_SOCKET_THREAD_SIZE_ATTRIBUTE:
+ node.get(Element.ODBC_MAX_SOCKET_THREAD_SIZE_ATTRIBUTE.getModelName()).set(Integer.parseInt(attrValue));
+ break;
+ case ODBC_IN_BUFFER_SIZE_ATTRIBUTE:
+ node.get(Element.ODBC_IN_BUFFER_SIZE_ATTRIBUTE.getModelName()).set(Integer.parseInt(attrValue));
+ break;
+ case ODBC_OUT_BUFFER_SIZE_ATTRIBUTE:
+ node.get(Element.ODBC_OUT_BUFFER_SIZE_ATTRIBUTE.getModelName()).set(Integer.parseInt(attrValue));
+ break;
+ default:
+ throw ParseUtils.unexpectedElement(reader);
+ }
+ }
+ }
+
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
- Element element = Element.forName(reader.getLocalName());
+ Element element = Element.forName(reader.getLocalName(), Configuration.ODBC);
switch (element) {
- case SSL_MODE_ELEMENT:
- case KEY_STORE_FILE_ELEMENT:
- case KEY_STORE_PASSWD_ELEMENT:
- case KEY_STORE_TYPE_ELEMENT:
- case SSL_PROTOCOL_ELEMENT:
- case TRUST_FILE_ELEMENT:
- case TRUST_PASSWD_ELEMENT:
- case AUTH_MODE_ELEMENT:
- case KEY_MANAGEMENT_ALG_ELEMENT:
- node.get(reader.getLocalName()).set(reader.getElementText());
+ case ODBC_SSL_ELEMENT:
+ parseODBCSSLConfiguration(reader, node);
break;
default:
throw ParseUtils.unexpectedElement(reader);
}
}
return node;
+ }
+
+ private ModelNode parseJDBCSSLConfiguration(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException {
+ while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
+ Element element = Element.forName(reader.getLocalName(), Configuration.JDBC, Configuration.SSL);
+ switch (element) {
+ case JDBC_SSL_MODE_ELEMENT:
+ node.get(Element.JDBC_SSL_MODE_ELEMENT.getModelName()).set(reader.getElementText());
+ break;
+ case JDBC_KEY_STORE_FILE_ELEMENT:
+ node.get(Element.JDBC_KEY_STORE_FILE_ELEMENT.getModelName()).set(reader.getElementText());
+ break;
+ case JDBC_KEY_STORE_PASSWD_ELEMENT:
+ node.get(Element.JDBC_KEY_STORE_PASSWD_ELEMENT.getModelName()).set(reader.getElementText());
+ break;
+ case JDBC_KEY_STORE_TYPE_ELEMENT:
+ node.get(Element.JDBC_KEY_STORE_TYPE_ELEMENT.getModelName()).set(reader.getElementText());
+ break;
+ case JDBC_SSL_PROTOCOL_ELEMENT:
+ node.get(Element.JDBC_SSL_PROTOCOL_ELEMENT.getModelName()).set(reader.getElementText());
+ break;
+ case JDBC_TRUST_FILE_ELEMENT:
+ node.get(Element.JDBC_TRUST_FILE_ELEMENT.getModelName()).set(reader.getElementText());
+ break;
+ case JDBC_TRUST_PASSWD_ELEMENT:
+ node.get(Element.JDBC_TRUST_PASSWD_ELEMENT.getModelName()).set(reader.getElementText());
+ break;
+ case JDBC_AUTH_MODE_ELEMENT:
+ node.get(Element.JDBC_AUTH_MODE_ELEMENT.getModelName()).set(reader.getElementText());
+ break;
+ case JDBC_KEY_MANAGEMENT_ALG_ELEMENT:
+ node.get(Element.JDBC_KEY_MANAGEMENT_ALG_ELEMENT.getModelName()).set(reader.getElementText());
+ break;
+ default:
+ throw ParseUtils.unexpectedElement(reader);
+ }
+ }
+ return node;
}
- private ModelNode parseTranslator(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException {
+ private ModelNode parseODBCSSLConfiguration(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException {
+ while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
+ Element element = Element.forName(reader.getLocalName(), Configuration.ODBC, Configuration.SSL);
+ switch (element) {
+ case ODBC_SSL_MODE_ELEMENT:
+ node.get(Element.ODBC_SSL_MODE_ELEMENT.getModelName()).set(reader.getElementText());
+ break;
+ case ODBC_KEY_STORE_FILE_ELEMENT:
+ node.get(Element.ODBC_KEY_STORE_FILE_ELEMENT.getModelName()).set(reader.getElementText());
+ break;
+ case ODBC_KEY_STORE_PASSWD_ELEMENT:
+ node.get(Element.ODBC_KEY_STORE_PASSWD_ELEMENT.getModelName()).set(reader.getElementText());
+ break;
+ case ODBC_KEY_STORE_TYPE_ELEMENT:
+ node.get(Element.ODBC_KEY_STORE_TYPE_ELEMENT.getModelName()).set(reader.getElementText());
+ break;
+ case ODBC_SSL_PROTOCOL_ELEMENT:
+ node.get(Element.ODBC_SSL_PROTOCOL_ELEMENT.getModelName()).set(reader.getElementText());
+ break;
+ case ODBC_TRUST_FILE_ELEMENT:
+ node.get(Element.ODBC_TRUST_FILE_ELEMENT.getModelName()).set(reader.getElementText());
+ break;
+ case ODBC_TRUST_PASSWD_ELEMENT:
+ node.get(Element.ODBC_TRUST_PASSWD_ELEMENT.getModelName()).set(reader.getElementText());
+ break;
+ case ODBC_AUTH_MODE_ELEMENT:
+ node.get(Element.ODBC_AUTH_MODE_ELEMENT.getModelName()).set(reader.getElementText());
+ break;
+ case ODBC_KEY_MANAGEMENT_ALG_ELEMENT:
+ node.get(Element.ODBC_KEY_MANAGEMENT_ALG_ELEMENT.getModelName()).set(reader.getElementText());
+ break;
+ default:
+ throw ParseUtils.unexpectedElement(reader);
+ }
+ }
+ return node;
+ }
+
+ private String parseTranslator(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException {
+ String translatorName = null;
if (reader.getAttributeCount() > 0) {
for(int i=0; i<reader.getAttributeCount(); i++) {
String attrName = reader.getAttributeLocalName(i);
@@ -510,6 +702,8 @@
Element element = Element.forName(attrName);
switch(element) {
case TRANSLATOR_NAME_ATTRIBUTE:
+ translatorName = attrValue;
+ break;
case TRANSLATOR_MODULE_ATTRIBUTE:
node.get(attrName).set(attrValue);
break;
@@ -521,6 +715,6 @@
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
throw ParseUtils.unexpectedElement(reader);
}
- return node;
+ return translatorName;
}
}
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TranslatorAdd.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TranslatorAdd.java 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TranslatorAdd.java 2011-09-28 15:25:16 UTC (rev 3505)
@@ -55,22 +55,18 @@
operation.get(OPERATION_NAME).set(ADD);
operation.get(DESCRIPTION).set(bundle.getString("translator.add")); //$NON-NLS-1$
- addAttribute(operation, Configuration.TRANSLATOR_MODULE, ATTRIBUTES, bundle.getString(Configuration.TRANSLATOR_MODULE+Configuration.DESC), ModelType.STRING, true, null);
+ addAttribute(operation, Configuration.TRANSLATOR_MODULE, REQUEST_PROPERTIES, bundle.getString(Configuration.TRANSLATOR_MODULE+Configuration.DESC), ModelType.STRING, true, null);
return operation;
}
@Override
protected void populateModel(final ModelNode operation, final ModelNode model) throws OperationFailedException{
- final ModelNode address = operation.require(OP_ADDR);
- final PathAddress pathAddress = PathAddress.pathAddress(address);
-
- populate(pathAddress.getLastElement().getValue(), operation, model);
+ populate(operation, model);
}
- static void populate(String name, ModelNode operation, ModelNode model) {
+ static void populate(ModelNode operation, ModelNode model) {
final String moduleName = operation.require(Configuration.TRANSLATOR_MODULE).asString();
- model.get(NAME).set(name);
- model.get(Configuration.TRANSLATOR_MODULE).set(moduleName);
+ model.get(Configuration.TRANSLATOR_MODULE).set(moduleName);
}
@Override
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/VDBParserDeployer.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/VDBParserDeployer.java 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/VDBParserDeployer.java 2011-09-28 15:25:16 UTC (rev 3505)
@@ -143,7 +143,7 @@
imf.addEntriesPlusVisibilities(file, vdb);
// This time stamp is used to check if the VDB is modified after the metadata is written to disk
- vdb.addProperty(VDBService.VDB_LASTMODIFIED_TIME, String.valueOf(file.getLastModified()));
+ //vdb.addProperty(VDBService.VDB_LASTMODIFIED_TIME, String.valueOf(file.getLastModified()));
}
if (udf != null) {
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2011-09-28 15:25:16 UTC (rev 3505)
@@ -59,7 +59,6 @@
import org.teiid.translator.TranslatorException;
class VDBService implements Service<VDBMetaData> {
- public static final String VDB_LASTMODIFIED_TIME = "VDB_LASTMODIFIED_TIME"; //$NON-NLS-1$
private VDBMetaData vdb;
private final InjectedValue<VDBRepository> vdbRepositoryInjector = new InjectedValue<VDBRepository>();
private final InjectedValue<TranslatorRepository> translatorRepositoryInjector = new InjectedValue<TranslatorRepository>();
@@ -81,10 +80,6 @@
// check if this is a VDB with index files, if there are then build the TransformationMetadata
UDFMetaData udf = this.vdb.getAttachment(UDFMetaData.class);
IndexMetadataFactory indexFactory = this.vdb.getAttachment(IndexMetadataFactory.class);
- long vdbModifiedTime = -1L;
- if (vdb.getPropertyValue(VDBService.VDB_LASTMODIFIED_TIME) != null) {
- vdbModifiedTime = Long.parseLong(vdb.getPropertyValue(VDBService.VDB_LASTMODIFIED_TIME));
- }
// add required connector managers; if they are not already there
for (Translator t: this.vdb.getOverrideTranslators()) {
@@ -105,10 +100,11 @@
createConnectorManagers(cmr, repo, this.vdb);
// check to see if the vdb has been modified when server is down; if it is then clear the old files
- if (vdbModifiedTime != -1L && getSerializer().isStale(this.vdb, vdbModifiedTime)) {
- getSerializer().removeAttachments(this.vdb);
- LogManager.logTrace(LogConstants.CTX_RUNTIME, "VDB ", vdb.getName(), " old cached metadata has been removed"); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ // This is no longer required as VDB can not modified in place in deployment directory as they held inside the data dir
+ //if (vdbModifiedTime != -1L && getSerializer().isStale(this.vdb, vdbModifiedTime)) {
+ // getSerializer().removeAttachments(this.vdb);
+ // LogManager.logTrace(LogConstants.CTX_RUNTIME, "VDB ", vdb.getName(), " old cached metadata has been removed"); //$NON-NLS-1$ //$NON-NLS-2$
+ //}
boolean asynchLoad = false;
boolean preview = this.vdb.isPreview();
Modified: branches/as7/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties
===================================================================
--- branches/as7/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties 2011-09-28 15:25:16 UTC (rev 3505)
@@ -116,10 +116,15 @@
Setting this value to LRU will cause cache hint TTL values \
to be ignored. (default EXPIRATION)
container-name.describe=Infinispan cache container name
+resultset-cache-name.describe = Infinispan cache name for resultset
#cache
resultset-cache.describe=Resultset cache
preparedplan-cache.describe=Prepared Plan cache
+
+#object replicator
+stack.describe=JGroups stack name for cache replication channel
+cluster-name.describe=cache channel cluster name for cache replication
#socket config
max-socket-threads.describe=Max number of threads dedicated to initial request processing. \
@@ -152,7 +157,7 @@
translator.describe = Teiid Translators
translator.add = Add Teiid translator
translator.remove = Remove Teiid translator
-teiid-boot.add = Teiid boot serviceshitRatio.describe
+teiid-boot.add = Teiid boot services
total-entries.describe = Total entries in Cache
hit-ratio.describe = Cache Hit ratio
Modified: branches/as7/jboss-integration/src/main/resources/schema/jboss-teiid.xsd
===================================================================
--- branches/as7/jboss-integration/src/main/resources/schema/jboss-teiid.xsd 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/jboss-integration/src/main/resources/schema/jboss-teiid.xsd 2011-09-28 15:25:16 UTC (rev 3505)
@@ -94,11 +94,20 @@
</xs:complexType>
</xs:element>
- <xs:element name="query-engine" type="runtime-engine-type" maxOccurs="2" minOccurs="1">
+ <xs:element name="query-engine" type="runtime-engine-type" maxOccurs="unbounded" minOccurs="0">
<xs:annotation>
<xs:documentation>Main Teiid runtime engine configuration</xs:documentation>
</xs:annotation>
</xs:element>
+ <xs:element name="translator" maxOccurs="unbounded" minOccurs="0">
+ <xs:annotation>
+ <xs:documentation>Translators defined in the system</xs:documentation>
+ </xs:annotation>
+ <xs:complexType>
+ <xs:attribute name="name" type="xs:string" use="required"/>
+ <xs:attribute name="module" type="xs:string" use="required"/>
+ </xs:complexType>
+ </xs:element>
</xs:sequence>
</xs:complexType>
@@ -243,30 +252,30 @@
<xs:complexType name="socket-config">
<xs:sequence>
- <xs:element name="max-socket-threads" type="xs:int" minOccurs="0" maxOccurs="1" default="0">
+ <xs:element name="ssl" type="ssl-config" minOccurs="0" maxOccurs="1">
<xs:annotation>
- <xs:documentation>Max number of threads dedicated to initial request processing.
- Zero indicates the system default of max available processors. (default 0)
- Setting this value above the max available processors is not recommended.</xs:documentation>
+ <xs:documentation>SSL Configuration</xs:documentation>
</xs:annotation>
</xs:element>
- <xs:element name="input-buffer-size" type="xs:int" minOccurs="0" maxOccurs="1" default="0">
+ </xs:sequence>
+ <xs:attribute name="socket-binding" type="xs:string" use="required"/>
+ <xs:attribute name="input-buffer-size" type="xs:int">
<xs:annotation>
<xs:documentation>SO_RCVBUF size, 0 indicates that system default should be used (default 0) </xs:documentation>
</xs:annotation>
- </xs:element>
- <xs:element name="output-buffer-size" type="xs:int" minOccurs="0" maxOccurs="1" default="0">
+ </xs:attribute>
+ <xs:attribute name="output-buffer-size" type="xs:string">
<xs:annotation>
<xs:documentation>SO_SNDBUF size, 0 indicates that system default should be used (default 0)</xs:documentation>
</xs:annotation>
- </xs:element>
- <xs:element name="ssl" type="ssl-config" minOccurs="0" maxOccurs="1">
+ </xs:attribute>
+ <xs:attribute name="max-socket-threads" type="xs:int">
<xs:annotation>
- <xs:documentation>SSL Configuration</xs:documentation>
- </xs:annotation>
- </xs:element>
- </xs:sequence>
- <xs:attribute name="socket-binding" type="xs:string" use="required"/>
+ <xs:documentation>Max number of threads dedicated to initial request processing.
+ Zero indicates the system default of max available processors. (default 0)
+ Setting this value above the max available processors is not recommended.</xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
</xs:complexType>
<xs:complexType name="ssl-config">
@@ -288,13 +297,6 @@
</xs:restriction>
</xs:simpleType>
</xs:element>
- <xs:element name="keystore-name" type="xs:string" minOccurs="0" maxOccurs="1" />
- <xs:element name="keystore-password" type="xs:string" minOccurs="0" maxOccurs="1" />
- <xs:element name="keystore-type" type="xs:string" minOccurs="0" maxOccurs="1" />
- <xs:element name="ssl-protocol" type="xs:string" minOccurs="0" maxOccurs="1" />
- <xs:element name="keymanagement-algorithm" type="xs:boolean" minOccurs="0" maxOccurs="1" />
- <xs:element name="truststore-name" type="xs:string" minOccurs="0" maxOccurs="1" />
- <xs:element name="truststore-password" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="authentication-mode" minOccurs="0" maxOccurs="1" default="anonymous">
<xs:annotation>
<xs:documentation>1-way, 2-way, anonymous</xs:documentation>
@@ -307,6 +309,13 @@
</xs:restriction>
</xs:simpleType>
</xs:element>
+ <xs:element name="ssl-protocol" type="xs:string" minOccurs="0" maxOccurs="1" />
+ <xs:element name="keymanagement-algorithm" type="xs:string" minOccurs="0" maxOccurs="1" />
+ <xs:element name="keystore-name" type="xs:string" minOccurs="0" maxOccurs="1" />
+ <xs:element name="keystore-password" type="xs:string" minOccurs="0" maxOccurs="1" />
+ <xs:element name="keystore-type" type="xs:string" minOccurs="0" maxOccurs="1" />
+ <xs:element name="truststore-name" type="xs:string" minOccurs="0" maxOccurs="1" />
+ <xs:element name="truststore-password" type="xs:string" minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
Added: branches/as7/jboss-integration/src/test/java/org/teiid/jboss/TestTeiidAdminOperations.java
===================================================================
--- branches/as7/jboss-integration/src/test/java/org/teiid/jboss/TestTeiidAdminOperations.java (rev 0)
+++ branches/as7/jboss-integration/src/test/java/org/teiid/jboss/TestTeiidAdminOperations.java 2011-09-28 15:25:16 UTC (rev 3505)
@@ -0,0 +1,207 @@
+package org.teiid.jboss;
+
+import static junit.framework.Assert.assertEquals;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.*;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayInputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+
+import junit.framework.Assert;
+
+import org.jboss.as.controller.OperationContext.Type;
+import org.jboss.as.controller.PathAddress;
+import org.jboss.as.controller.PathElement;
+import org.jboss.as.subsystem.test.AbstractSubsystemTest;
+import org.jboss.as.subsystem.test.AdditionalInitialization;
+import org.jboss.as.subsystem.test.KernelServices;
+import org.jboss.dmr.ModelNode;
+import org.junit.Test;
+import org.teiid.core.util.ObjectConverterUtil;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+@SuppressWarnings("nls")
+public class TestTeiidAdminOperations extends AbstractSubsystemTest {
+
+ public TestTeiidAdminOperations() {
+ super(TeiidExtension.TEIID_SUBSYSTEM, new TeiidExtension());
+ }
+
+ @Test
+ public void testDescribeHandler() throws Exception {
+ //Parse the subsystem xml and install into the first controller
+ String subsystemXml ="<subsystem xmlns=\"urn:jboss:domain:teiid:1.0\">" +
+ "<async-thread-group>async</async-thread-group>"+
+ " <query-engine name=\"default\">" +
+ " </query-engine>" +
+ "</subsystem>";
+ KernelServices servicesA = super.installInController(subsystemXml);
+ //Get the model and the describe operations from the first controller
+ ModelNode modelA = servicesA.readWholeModel();
+ String marshalled = servicesA.getPersistedSubsystemXml();
+
+ ModelNode describeOp = new ModelNode();
+ describeOp.get(OP).set(DESCRIBE);
+ describeOp.get(OP_ADDR).set(
+ PathAddress.pathAddress(
+ PathElement.pathElement(SUBSYSTEM, TeiidExtension.TEIID_SUBSYSTEM)).toModelNode());
+ List<ModelNode> operations = super.checkResultAndGetContents(servicesA.executeOperation(describeOp)).asList();
+
+
+ //Install the describe options from the first controller into a second controller
+ KernelServices servicesB = super.installInController(operations);
+ ModelNode modelB = servicesB.readWholeModel();
+
+ //Make sure the models from the two controllers are identical
+ super.compare(modelA, modelB);
+ }
+
+ @Test
+ public void testOutputPerisitence() throws Exception {
+ String subsystemXml = ObjectConverterUtil.convertToString(new FileReader("src/test/resources/teiid-sample-config.xml"));
+
+ String json = ObjectConverterUtil.convertToString(new FileReader("src/test/resources/teiid-model-json.txt"));
+ ModelNode testModel = ModelNode.fromJSONString(json);
+ String triggered = outputModel(testModel);
+
+ KernelServices services = super.installInController(
+ new AdditionalInitialization() {
+ @Override
+ protected Type getType() {
+ return Type.MANAGEMENT;
+ }
+ },
+ subsystemXml);
+ //Get the model and the persisted xml from the controller
+ ModelNode model = services.readWholeModel();
+ String marshalled = services.getPersistedSubsystemXml();
+
+ System.out.println(marshalled);
+
+ Assert.assertEquals(marshalled, triggered);
+ Assert.assertEquals(normalizeXML(marshalled), normalizeXML(triggered));
+ }
+
+ @Test
+ public void testOutputModel() throws Exception {
+ String subsystemXml = ObjectConverterUtil.convertToString(new FileReader("src/test/resources/teiid-sample-config.xml"));
+
+ String json = ObjectConverterUtil.convertToString(new FileReader("src/test/resources/teiid-model-json.txt"));
+ ModelNode testModel = ModelNode.fromJSONString(json);
+ String triggered = outputModel(testModel);
+
+ KernelServices services = super.installInController(
+ new AdditionalInitialization() {
+ @Override
+ protected Type getType() {
+ return Type.MANAGEMENT;
+ }
+ },
+ subsystemXml);
+ //Get the model and the persisted xml from the controller
+ ModelNode model = services.readWholeModel();
+ String marshalled = services.getPersistedSubsystemXml();
+
+ Assert.assertEquals(marshalled, triggered);
+ Assert.assertEquals(normalizeXML(marshalled), normalizeXML(triggered));
+ }
+
+ @Test
+ public void testSchema() throws Exception {
+ String subsystemXml = ObjectConverterUtil.convertToString(new FileReader("src/test/resources/teiid-sample-config.xml"));
+ KernelServices services = super.installInController(
+ new AdditionalInitialization() {
+ @Override
+ protected Type getType() {
+ return Type.MANAGEMENT;
+ }
+ },
+ subsystemXml);
+ //Get the model and the persisted xml from the controller
+ ModelNode model = services.readWholeModel();
+ String marshalled = services.getPersistedSubsystemXml();
+
+ URL xsdURL = Thread.currentThread().getContextClassLoader().getResource("schema/jboss-teiid.xsd");
+
+ SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
+ Schema schema = factory.newSchema(xsdURL);
+
+ Validator validator = schema.newValidator();
+ Source source = new StreamSource(new ByteArrayInputStream(marshalled.getBytes()));
+ validator.setErrorHandler(new ErrorHandler() {
+
+ @Override
+ public void warning(SAXParseException exception) throws SAXException {
+ fail(exception.getMessage());
+ }
+
+ @Override
+ public void fatalError(SAXParseException exception) throws SAXException {
+ fail(exception.getMessage());
+ }
+
+ @Override
+ public void error(SAXParseException exception) throws SAXException {
+ if (!exception.getMessage().contains("cvc-enumeration-valid") && !exception.getMessage().contains("cvc-type"))
+ fail(exception.getMessage());
+ }
+ });
+
+ validator.validate(source);
+ }
+
+ @Test
+ public void testSubSystemDescription() throws IOException {
+ ModelNode node = new ModelNode();
+ QueryEngineAdd.describeQueryEngine(node, ATTRIBUTES, IntegrationPlugin.getResourceBundle(null));
+ assertEquals(ObjectConverterUtil.convertToString(new FileReader("src/test/resources/teiid-model-config.txt")), node.toString());
+ }
+
+ @Test
+ public void testParseSubsystem() throws Exception {
+ //Parse the subsystem xml into operations
+ String subsystemXml = ObjectConverterUtil.convertToString(new FileReader("src/test/resources/teiid-sample-config.xml"));
+ List<ModelNode> operations = super.parse(subsystemXml);
+
+ ///Check that we have the expected number of operations
+ Assert.assertEquals(5, operations.size());
+
+ //Check that each operation has the correct content
+ ModelNode addSubsystem = operations.get(0);
+ Assert.assertEquals(ADD, addSubsystem.get(OP).asString());
+ PathAddress addr = PathAddress.pathAddress(addSubsystem.get(OP_ADDR));
+ Assert.assertEquals(1, addr.size());
+ PathElement element = addr.getElement(0);
+ Assert.assertEquals(SUBSYSTEM, element.getKey());
+ Assert.assertEquals(TeiidExtension.TEIID_SUBSYSTEM, element.getValue());
+ }
+
+ @Test
+ public void testOperatrions() throws Exception {
+ String subsystemXml = ObjectConverterUtil.convertToString(new FileReader("src/test/resources/teiid-sample-config.xml"));
+
+ String json = ObjectConverterUtil.convertToString(new FileReader("src/test/resources/teiid-model-json.txt"));
+ ModelNode testModel = ModelNode.fromJSONString(json);
+ String triggered = outputModel(testModel);
+
+ KernelServices services = super.installInController(
+ new AdditionalInitialization() {
+ @Override
+ protected Type getType() {
+ return Type.MANAGEMENT;
+ }
+ },
+ subsystemXml);
+ }
+}
Property changes on: branches/as7/jboss-integration/src/test/java/org/teiid/jboss/TestTeiidAdminOperations.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: branches/as7/jboss-integration/src/test/java/org/teiid/jboss/TestTeiidConfiguration.java
===================================================================
--- branches/as7/jboss-integration/src/test/java/org/teiid/jboss/TestTeiidConfiguration.java 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/jboss-integration/src/test/java/org/teiid/jboss/TestTeiidConfiguration.java 2011-09-28 15:25:16 UTC (rev 3505)
@@ -81,7 +81,6 @@
profileAddress.add("profile", "test");
}
- @Test
public void testValidateSchema() throws Exception {
InputStream content = Thread.currentThread().getContextClassLoader().getResourceAsStream("teiid-sample-config.xml");
URL xsdURL = Thread.currentThread().getContextClassLoader().getResource("schema/jboss-teiid.xsd");
@@ -113,7 +112,6 @@
}
- @Test
public void testTeiidConfiguration() throws Exception {
List<ModelNode> updates = createSubSystem(ObjectConverterUtil.convertToString(new FileReader("src/test/resources/teiid-sample-config.xml")));
assertEquals(3, updates.size());
@@ -371,22 +369,7 @@
return rsp.get(RESULT);
}
- public void susbsytemParserDeparser(String xmlContent) throws Exception {
- XMLMapper xmlMapper = XMLMapper.Factory.create();
- List<ModelNode> updates = createSubSystem(xmlContent);
-
- StringWriter sw = new StringWriter();
- XMLStreamWriter streamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(sw);
- xmlMapper.deparseDocument(new TeiidSubsystemParser(), new SubsystemMarshallingContext(updates.get(1), new MockXMLExtendedWriter(streamWriter)), streamWriter);
-
- System.out.println(sw.toString());
- }
- //@Test
- public void testXMLPersistence() throws Exception {
- susbsytemParserDeparser(ObjectConverterUtil.convertToString(new FileReader("src/test/resources/teiid-sample-config.xml")));
- }
-
@Test
public void testSubSystemDescription() throws IOException {
ModelNode node = new ModelNode();
Modified: branches/as7/jboss-integration/src/test/resources/teiid-model-config.txt
===================================================================
--- branches/as7/jboss-integration/src/test/resources/teiid-model-config.txt 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/jboss-integration/src/test/resources/teiid-model-config.txt 2011-09-28 15:25:16 UTC (rev 3505)
@@ -1,307 +1,269 @@
-{
- "attributes" => {
- "max-threads" => {
- "type" => INT,
- "description" => "Process pool maximum thread count. (default 64)",
- "required" => false,
- "max-occurs" => 1,
- "default" => 64
- },
- "max-active-plans" => {
- "type" => INT,
- "description" => "Max active plans (default 20). Increase this value on highly concurrent systems - but ensure that the underlying pools can handle the increased load without timeouts.",
- "required" => false,
- "max-occurs" => 1,
- "default" => 20
- },
- "thread-count-for-source-concurrency" => {
- "type" => INT,
- "description" => "Max source query concurrency per user request (default 0). 0 indicates use the default calculated value based on max active plans and max threads - approximately 2*(max threads)/(max active plans). ",
- "required" => false,
- "max-occurs" => 1,
- "default" => 0
- },
- "time-slice-in-millseconds" => {
- "type" => INT,
- "description" => "Query processor time slice, in milliseconds. (default 2000)",
- "required" => false,
- "max-occurs" => 1,
- "default" => 2000
- },
- "max-row-fetch-size" => {
- "type" => INT,
- "description" => "Maximum allowed fetch size, set via JDBC. User requested value ignored above this value. (default 20480)",
- "required" => false,
- "max-occurs" => 1,
- "default" => 20480
- },
- "lob-chunk-size-in-kb" => {
- "type" => INT,
- "description" => "The max lob chunk size in KB transferred each time when processing blobs, clobs (100KB default)",
- "required" => false,
- "max-occurs" => 1,
- "default" => 100
- },
- "query-threshold-in-seconds" => {
- "type" => INT,
- "description" => "Long running query threshold, after which a alert can be generated by tooling if configured",
- "required" => false,
- "max-occurs" => 1,
- "default" => 600
- },
- "max-source-rows-allowed" => {
- "type" => INT,
- "description" => "Maximum rows allowed from a source query. -1 indicates no limit. (default -1)",
- "required" => false,
- "max-occurs" => 1,
- "default" => -1
- },
- "exception-on-max-source-rows" => {
- "type" => BOOLEAN,
- "description" => "Indicates if an exception should be thrown if the specified value for Maximum Source Rows is exceeded; only up to the maximum rows will be consumed. (default true)",
- "required" => false,
- "max-occurs" => 1,
- "default" => true
- },
- "max-odbc-lob-size-allowed" => {
- "type" => INT,
- "description" => "Maximum size of lob allowed through ODBC connection in bytes (default 5MB)",
- "required" => false,
- "max-occurs" => 1,
- "default" => 5242880
- },
- "detect-change-events" => {
- "type" => BOOLEAN,
- "description" => "Set to true for the engine to detect local change events. Should be disabled if using external change data capture tools. (default true)",
- "required" => false,
- "max-occurs" => 1,
- "default" => true
- },
- "security-domain" => {
- "type" => LIST,
- "description" => "List of domains to be used to login into Teiid",
- "required" => false,
- "max-occurs" => 1
- },
- "max-sessions-allowed" => {
- "type" => INT,
- "description" => "Maximum number of sessions allowed by the system (default 5000)",
- "required" => false,
- "max-occurs" => 1,
- "default" => 5000
- },
- "sessions-expiration-timelimit" => {
- "type" => INT,
- "description" => "Max allowed time before the session is terminated by the system, 0 indicates unlimited (default 0)",
- "required" => false,
- "max-occurs" => 1,
- "default" => 0
- }
+{"attributes" => {
+ "max-threads" => {
+ "type" => INT,
+ "description" => "Process pool maximum thread count. (default 64)",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => 64
},
- "children" => {
- "jdbc" => {
- "type" => OBJECT,
- "description" => "Remote JDBC Access Configuration ",
- "required" => false,
- "max-occurs" => 1,
- "min-occurs" => 1,
- "attributes" => {
- "max-socket-threads" => {
- "type" => INT,
- "description" => "Max number of threads dedicated to initial request processing. Zero indicates the system default of max available processors. (default 0) Setting this value above the max available processors is not recommended.",
- "required" => false,
- "max-occurs" => 1,
- "default" => 0
- },
- "input-buffer-size" => {
- "type" => INT,
- "description" => "SO_RCVBUF size, 0 indicates that system default should be used (default 0)",
- "required" => false,
- "max-occurs" => 1,
- "default" => 0
- },
- "output-buffer-size" => {
- "type" => INT,
- "description" => "SO_SNDBUF size, 0 indicates that system default should be used (default 0)",
- "required" => false,
- "max-occurs" => 1,
- "default" => 0
- },
- "socket-binding" => {
- "type" => STRING,
- "description" => "Socket binding for the profile",
- "required" => true,
- "max-occurs" => 1
- },
- "mode" => {
- "type" => STRING,
- "description" => "can be one of disabled, login, or enabled disabled = no transport or message level security will be used; login = only the login traffic will be encrypted at a message level using 128 bit AES with an ephemerial DH key exchange. No other config values are needed in this mode; enabled = traffic will be secured using this configuration,if the client supports SSL",
- "required" => false,
- "max-occurs" => 1,
- "default" => "login"
- },
- "keystore-name" => {
- "type" => STRING,
- "description" => "Keystore File Name",
- "required" => false,
- "max-occurs" => 1
- },
- "keystore-password" => {
- "type" => STRING,
- "description" => "Keystore password",
- "required" => false,
- "max-occurs" => 1
- },
- "keystore-type" => {
- "type" => STRING,
- "description" => "Keystore type",
- "required" => false,
- "max-occurs" => 1,
- "default" => "JKS"
- },
- "ssl-protocol" => {
- "type" => BOOLEAN,
- "description" => "SSL protocol used",
- "required" => false,
- "max-occurs" => 1,
- "default" => false
- },
- "keymanagement-algorithm" => {
- "type" => STRING,
- "description" => "Use key management algorithm",
- "required" => false,
- "max-occurs" => 1,
- "default" => "false"
- },
- "truststore-name" => {
- "type" => STRING,
- "description" => "Truststore Name",
- "required" => false,
- "max-occurs" => 1
- },
- "truststore-password" => {
- "type" => STRING,
- "description" => "Truststore Password",
- "required" => false,
- "max-occurs" => 1
- },
- "authentication-mode" => {
- "type" => STRING,
- "description" => "Authentication Mode (1-way, 2-way, anonymous)",
- "required" => false,
- "max-occurs" => 1,
- "default" => "anonymous"
- }
- },
- "children" => {"ssl" => {
- "type" => OBJECT,
- "description" => "SSL",
- "required" => false,
- "max-occurs" => 1,
- "min-occurs" => 0
- }}
- },
- "odbc" => {
- "type" => OBJECT,
- "description" => "ODBC Access Configuration",
- "required" => false,
- "max-occurs" => 1,
- "min-occurs" => 1,
- "attributes" => {
- "max-socket-threads" => {
- "type" => INT,
- "description" => "Max number of threads dedicated to initial request processing. Zero indicates the system default of max available processors. (default 0) Setting this value above the max available processors is not recommended.",
- "required" => false,
- "max-occurs" => 1,
- "default" => 0
- },
- "input-buffer-size" => {
- "type" => INT,
- "description" => "SO_RCVBUF size, 0 indicates that system default should be used (default 0)",
- "required" => false,
- "max-occurs" => 1,
- "default" => 0
- },
- "output-buffer-size" => {
- "type" => INT,
- "description" => "SO_SNDBUF size, 0 indicates that system default should be used (default 0)",
- "required" => false,
- "max-occurs" => 1,
- "default" => 0
- },
- "socket-binding" => {
- "type" => STRING,
- "description" => "Socket binding for the profile",
- "required" => true,
- "max-occurs" => 1
- },
- "mode" => {
- "type" => STRING,
- "description" => "can be one of disabled, login, or enabled disabled = no transport or message level security will be used; login = only the login traffic will be encrypted at a message level using 128 bit AES with an ephemerial DH key exchange. No other config values are needed in this mode; enabled = traffic will be secured using this configuration,if the client supports SSL",
- "required" => false,
- "max-occurs" => 1,
- "default" => "login"
- },
- "keystore-name" => {
- "type" => STRING,
- "description" => "Keystore File Name",
- "required" => false,
- "max-occurs" => 1
- },
- "keystore-password" => {
- "type" => STRING,
- "description" => "Keystore password",
- "required" => false,
- "max-occurs" => 1
- },
- "keystore-type" => {
- "type" => STRING,
- "description" => "Keystore type",
- "required" => false,
- "max-occurs" => 1,
- "default" => "JKS"
- },
- "ssl-protocol" => {
- "type" => BOOLEAN,
- "description" => "SSL protocol used",
- "required" => false,
- "max-occurs" => 1,
- "default" => false
- },
- "keymanagement-algorithm" => {
- "type" => STRING,
- "description" => "Use key management algorithm",
- "required" => false,
- "max-occurs" => 1,
- "default" => "false"
- },
- "truststore-name" => {
- "type" => STRING,
- "description" => "Truststore Name",
- "required" => false,
- "max-occurs" => 1
- },
- "truststore-password" => {
- "type" => STRING,
- "description" => "Truststore Password",
- "required" => false,
- "max-occurs" => 1
- },
- "authentication-mode" => {
- "type" => STRING,
- "description" => "Authentication Mode (1-way, 2-way, anonymous)",
- "required" => false,
- "max-occurs" => 1,
- "default" => "anonymous"
- }
- },
- "children" => {"ssl" => {
- "type" => OBJECT,
- "description" => "SSL",
- "required" => false,
- "max-occurs" => 1,
- "min-occurs" => 0
- }}
- }
+ "max-active-plans" => {
+ "type" => INT,
+ "description" => "Max active plans (default 20). Increase this value on highly concurrent systems - but ensure that the underlying pools can handle the increased load without timeouts.",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => 20
+ },
+ "thread-count-for-source-concurrency" => {
+ "type" => INT,
+ "description" => "Max source query concurrency per user request (default 0). 0 indicates use the default calculated value based on max active plans and max threads - approximately 2*(max threads)/(max active plans). ",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => 0
+ },
+ "time-slice-in-millseconds" => {
+ "type" => INT,
+ "description" => "Query processor time slice, in milliseconds. (default 2000)",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => 2000
+ },
+ "max-row-fetch-size" => {
+ "type" => INT,
+ "description" => "Maximum allowed fetch size, set via JDBC. User requested value ignored above this value. (default 20480)",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => 20480
+ },
+ "lob-chunk-size-in-kb" => {
+ "type" => INT,
+ "description" => "The max lob chunk size in KB transferred each time when processing blobs, clobs (100KB default)",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => 100
+ },
+ "query-threshold-in-seconds" => {
+ "type" => INT,
+ "description" => "Long running query threshold, after which a alert can be generated by tooling if configured",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => 600
+ },
+ "max-source-rows-allowed" => {
+ "type" => INT,
+ "description" => "Maximum rows allowed from a source query. -1 indicates no limit. (default -1)",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => -1
+ },
+ "exception-on-max-source-rows" => {
+ "type" => BOOLEAN,
+ "description" => "Indicates if an exception should be thrown if the specified value for Maximum Source Rows is exceeded; only up to the maximum rows will be consumed. (default true)",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => true
+ },
+ "max-odbc-lob-size-allowed" => {
+ "type" => INT,
+ "description" => "Maximum size of lob allowed through ODBC connection in bytes (default 5MB)",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => 5242880
+ },
+ "detect-change-events" => {
+ "type" => BOOLEAN,
+ "description" => "Set to true for the engine to detect local change events. Should be disabled if using external change data capture tools. (default true)",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => true
+ },
+ "security-domain" => {
+ "type" => LIST,
+ "description" => "List of domains to be used to login into Teiid",
+ "required" => false,
+ "max-occurs" => 1
+ },
+ "max-sessions-allowed" => {
+ "type" => INT,
+ "description" => "Maximum number of sessions allowed by the system (default 5000)",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => 5000
+ },
+ "sessions-expiration-timelimit" => {
+ "type" => INT,
+ "description" => "Max allowed time before the session is terminated by the system, 0 indicates unlimited (default 0)",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => 0
+ },
+ "jdbc-max-socket-threads" => {
+ "type" => INT,
+ "description" => "Max number of threads dedicated to initial request processing. Zero indicates the system default of max available processors. (default 0) Setting this value above the max available processors is not recommended.",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => 0
+ },
+ "jdbc-input-buffer-size" => {
+ "type" => INT,
+ "description" => "SO_RCVBUF size, 0 indicates that system default should be used (default 0)",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => 0
+ },
+ "jdbc-output-buffer-size" => {
+ "type" => INT,
+ "description" => "SO_SNDBUF size, 0 indicates that system default should be used (default 0)",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => 0
+ },
+ "jdbc-socket-binding" => {
+ "type" => STRING,
+ "description" => "Socket binding for the profile",
+ "required" => false,
+ "max-occurs" => 1
+ },
+ "jdbc-ssl-mode" => {
+ "type" => STRING,
+ "description" => "can be one of disabled, login, or enabled disabled = no transport or message level security will be used; login = only the login traffic will be encrypted at a message level using 128 bit AES with an ephemerial DH key exchange. No other config values are needed in this mode; enabled = traffic will be secured using this configuration,if the client supports SSL",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => "login"
+ },
+ "jdbc-ssl-keystore-name" => {
+ "type" => STRING,
+ "description" => "Keystore File Name",
+ "required" => false,
+ "max-occurs" => 1
+ },
+ "jdbc-ssl-keystore-password" => {
+ "type" => STRING,
+ "description" => "Keystore password",
+ "required" => false,
+ "max-occurs" => 1
+ },
+ "jdbc-ssl-keystore-type" => {
+ "type" => STRING,
+ "description" => "Keystore type",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => "JKS"
+ },
+ "jdbc-ssl-ssl-protocol" => {
+ "type" => STRING,
+ "description" => "SSL protocol used",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => "SSLv3"
+ },
+ "jdbc-ssl-keymanagement-algorithm" => {
+ "type" => STRING,
+ "description" => "Use key management algorithm",
+ "required" => false,
+ "max-occurs" => 1
+ },
+ "jdbc-ssl-truststore-name" => {
+ "type" => STRING,
+ "description" => "Truststore Name",
+ "required" => false,
+ "max-occurs" => 1
+ },
+ "jdbc-ssl-truststore-password" => {
+ "type" => STRING,
+ "description" => "Truststore Password",
+ "required" => false,
+ "max-occurs" => 1
+ },
+ "jdbc-ssl-authentication-mode" => {
+ "type" => STRING,
+ "description" => "Authentication Mode (1-way, 2-way, anonymous)",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => "anonymous"
+ },
+ "odbc-max-socket-threads" => {
+ "type" => INT,
+ "description" => "Max number of threads dedicated to initial request processing. Zero indicates the system default of max available processors. (default 0) Setting this value above the max available processors is not recommended.",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => 0
+ },
+ "odbc-input-buffer-size" => {
+ "type" => INT,
+ "description" => "SO_RCVBUF size, 0 indicates that system default should be used (default 0)",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => 0
+ },
+ "odbc-output-buffer-size" => {
+ "type" => INT,
+ "description" => "SO_SNDBUF size, 0 indicates that system default should be used (default 0)",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => 0
+ },
+ "odbc-socket-binding" => {
+ "type" => STRING,
+ "description" => "Socket binding for the profile",
+ "required" => false,
+ "max-occurs" => 1
+ },
+ "odbc-ssl-mode" => {
+ "type" => STRING,
+ "description" => "can be one of disabled, login, or enabled disabled = no transport or message level security will be used; login = only the login traffic will be encrypted at a message level using 128 bit AES with an ephemerial DH key exchange. No other config values are needed in this mode; enabled = traffic will be secured using this configuration,if the client supports SSL",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => "login"
+ },
+ "odbc-ssl-keystore-name" => {
+ "type" => STRING,
+ "description" => "Keystore File Name",
+ "required" => false,
+ "max-occurs" => 1
+ },
+ "odbc-ssl-keystore-password" => {
+ "type" => STRING,
+ "description" => "Keystore password",
+ "required" => false,
+ "max-occurs" => 1
+ },
+ "odbc-ssl-keystore-type" => {
+ "type" => STRING,
+ "description" => "Keystore type",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => "JKS"
+ },
+ "odbc-ssl-ssl-protocol" => {
+ "type" => STRING,
+ "description" => "SSL protocol used",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => "SSLv3"
+ },
+ "odbc-ssl-keymanagement-algorithm" => {
+ "type" => STRING,
+ "description" => "Use key management algorithm",
+ "required" => false,
+ "max-occurs" => 1
+ },
+ "odbc-ssl-truststore-name" => {
+ "type" => STRING,
+ "description" => "Truststore Name",
+ "required" => false,
+ "max-occurs" => 1
+ },
+ "odbc-ssl-truststore-password" => {
+ "type" => STRING,
+ "description" => "Truststore Password",
+ "required" => false,
+ "max-occurs" => 1
+ },
+ "odbc-ssl-authentication-mode" => {
+ "type" => STRING,
+ "description" => "Authentication Mode (1-way, 2-way, anonymous)",
+ "required" => false,
+ "max-occurs" => 1,
+ "default" => "anonymous"
}
-}
\ No newline at end of file
+}}
\ No newline at end of file
Added: branches/as7/jboss-integration/src/test/resources/teiid-model-json.txt
===================================================================
--- branches/as7/jboss-integration/src/test/resources/teiid-model-json.txt (rev 0)
+++ branches/as7/jboss-integration/src/test/resources/teiid-model-json.txt 2011-09-28 15:25:16 UTC (rev 3505)
@@ -0,0 +1,64 @@
+{"subsystem" : {"teiid" : {
+ "allow-env-function" : "false",
+ "async-thread-group" : "teiid-async",
+ "buffer-service-connector-batch-size" : "1024",
+ "buffer-service-max-buffer-space" : "51200",
+ "buffer-service-max-file-size" : "2048",
+ "buffer-service-max-open-files" : "64",
+ "buffer-service-max-processing-kb" : "-1",
+ "buffer-service-max-reserve-kb" : "-1",
+ "buffer-service-processor-batch-size" : "512",
+ "buffer-service-use-disk" : "true",
+ "object-replicator-cluster-name" : "cluster",
+ "object-replicator-stack" : "stack",
+ "preparedplan-cache-max-age-in-seconds" : 28800,
+ "preparedplan-cache-max-entries" : 512,
+ "preparedplan-cache-max-staleness" : 90,
+ "resultset-cache-container-name" : "container",
+ "resultset-cache-enable" : false,
+ "resultset-cache-max-staleness" : 90,
+ "resultset-cache-name" : "cache",
+ "query-engine" : {
+ "alternate" : {},
+ "default" : {
+ "detect-change-events" : true,
+ "exception-on-max-source-rows" : true,
+ "jdbc-input-buffer-size" : 2,
+ "jdbc-max-socket-threads" : 1,
+ "jdbc-output-buffer-size" : 3,
+ "jdbc-socket-binding" : "teiid-jdbc",
+ "lob-chunk-size-in-kb" : 100,
+ "max-active-plans" : 20,
+ "max-odbc-lob-size-allowed" : 5242880,
+ "max-row-fetch-size" : 20480,
+ "max-sessions-allowed" : 5000,
+ "max-source-rows-allowed" : -1,
+ "max-threads" : 64,
+ "odbc-input-buffer-size" : 2,
+ "odbc-max-socket-threads" : 1,
+ "odbc-output-buffer-size" : 3,
+ "odbc-socket-binding" : "teiid-odbc",
+ "odbc-ssl-authentication-mode" : "1-way",
+ "odbc-ssl-keymanagement-algorithm" : "algo",
+ "odbc-ssl-keystore-name" : "keystore-name",
+ "odbc-ssl-keystore-password" : "keystore passs",
+ "odbc-ssl-keystore-type" : "key store type",
+ "odbc-ssl-mode" : "login",
+ "odbc-ssl-ssl-protocol" : "ssl protocol",
+ "odbc-ssl-truststore-name" : "truststore name",
+ "odbc-ssl-truststore-password" : "trust pass",
+ "query-threshold-in-seconds" : 600,
+ "security-domain" : [
+ "teiid-security",
+ "teiid-security2"
+ ],
+ "sessions-expiration-timelimit" : 0,
+ "thread-count-for-source-concurrency" : 0,
+ "time-slice-in-millseconds" : 2000
+ }
+ },
+ "translator" : {
+ "jdbc-simple" : {"module" : "org.jboss.teiid.translator.jdbc"},
+ "jdbc-ansi" : {"module" : "org.jboss.teiid.translator.jdbc"}
+ }
+}}}
\ No newline at end of file
Property changes on: branches/as7/jboss-integration/src/test/resources/teiid-model-json.txt
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: branches/as7/jboss-integration/src/test/resources/teiid-sample-config.xml
===================================================================
--- branches/as7/jboss-integration/src/test/resources/teiid-sample-config.xml 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/jboss-integration/src/test/resources/teiid-sample-config.xml 2011-09-28 15:25:16 UTC (rev 3505)
@@ -40,19 +40,25 @@
<max-sessions-allowed>5000</max-sessions-allowed>
<sessions-expiration-timelimit>0</sessions-expiration-timelimit>
- <jdbc socket-binding="teiid-jdbc">
- <max-socket-threads>0</max-socket-threads>
- <input-buffer-size>0</input-buffer-size>
- <output-buffer-size>0</output-buffer-size>
- </jdbc>
+ <jdbc socket-binding="teiid-jdbc" max-socket-threads="1" input-buffer-size="2" output-buffer-size="3"/>
- <odbc socket-binding="teiid-odbc">
- <max-socket-threads>0</max-socket-threads>
- <input-buffer-size>0</input-buffer-size>
- <output-buffer-size>0</output-buffer-size>
+ <odbc socket-binding="teiid-odbc" max-socket-threads="1" input-buffer-size="2" output-buffer-size="3">
+ <ssl>
+ <mode>login</mode>
+ <keystore-name>keystore-name</keystore-name>
+ <keystore-password>keystore passs</keystore-password>
+ <keystore-type>key store type</keystore-type>
+ <ssl-protocol>ssl protocol</ssl-protocol>
+ <keymanagement-algorithm>algo</keymanagement-algorithm>
+ <truststore-name>truststore name</truststore-name>
+ <truststore-password>trust pass</truststore-password>
+ <authentication-mode>1-way</authentication-mode>
+ </ssl>
</odbc>
</query-engine>
<query-engine name="alternate"/>
+ <translator name="jdbc-simple" module="org.jboss.teiid.translator.jdbc"/>
+ <translator name="jdbc-ansi" module="org.jboss.teiid.translator.jdbc"/>
</subsystem>
\ No newline at end of file
Modified: branches/as7/pom.xml
===================================================================
--- branches/as7/pom.xml 2011-09-28 03:15:08 UTC (rev 3504)
+++ branches/as7/pom.xml 2011-09-28 15:25:16 UTC (rev 3505)
@@ -455,8 +455,13 @@
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-clustering-jgroups</artifactId>
<version>${jbossas-version}</version>
- </dependency>
+ </dependency>
<dependency>
+ <groupId>org.jboss.as</groupId>
+ <artifactId>jboss-as-subsystem-test</artifactId>
+ <version>${jbossas-version}</version>
+ </dependency>
+ <dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
<version>5.0.0.FINAL</version>
[View Less]
13 years, 6 months
teiid SVN: r3504 - in trunk: engine/src/main/java/org/teiid/common/buffer and 5 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-09-27 23:15:08 -0400 (Tue, 27 Sep 2011)
New Revision: 3504
Added:
trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockBitSetTree.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockClosedLongIntHashTable.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockManager.java
trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockBitSetTree.java
trunk/engine/src/test/java/org/teiid/common/buffer/impl/…
[View More]TestBlockClosedLongIntHashTable.java
Removed:
trunk/engine/src/main/java/org/teiid/common/buffer/impl/BitSetTree.java
trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBitSetTree.java
Modified:
trunk/common-core/src/test/java/org/teiid/core/util/UnitTestUtil.java
trunk/engine/src/main/java/org/teiid/common/buffer/Cache.java
trunk/engine/src/main/java/org/teiid/common/buffer/FileStore.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/ExtensibleBufferedOutputStream.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStorageManager.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStoreCache.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/MemoryStorageManager.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java
trunk/engine/src/test/java/org/teiid/common/buffer/BufferManagerFactory.java
trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStoreCache.java
trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestSizeUtility.java
trunk/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewReplication.java
Log:
TEIID-1750 converting storage over to a more flexible inode approach
Modified: trunk/common-core/src/test/java/org/teiid/core/util/UnitTestUtil.java
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/util/UnitTestUtil.java 2011-09-23 04:11:11 UTC (rev 3503)
+++ trunk/common-core/src/test/java/org/teiid/core/util/UnitTestUtil.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -28,7 +28,16 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.io.PrintWriter;
import java.io.Serializable;
+import java.io.Writer;
+import java.sql.Timestamp;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Formatter;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
@@ -388,6 +397,7 @@
return filePath;
}
+ @SuppressWarnings("unchecked")
public static final <T extends Serializable> T helpSerialize(T object) throws IOException, ClassNotFoundException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
@@ -398,5 +408,59 @@
return (T)ois.readObject();
}
+
+ public static void enableTraceLogging(String loggerName) {
+ Logger logger = Logger.getLogger(loggerName);
+ logger.setLevel(Level.FINEST);
+ if (logger.getHandlers().length > 0) {
+ for (Handler h : logger.getHandlers()) {
+ h.setLevel(Level.FINEST);
+ }
+ } else {
+ logger.setUseParentHandlers(false);
+ ConsoleHandler ch = new ConsoleHandler();
+ ch.setFormatter(new Formatter() {
+
+ @Override
+ public String format(LogRecord record) {
+ final StringBuilder result = new StringBuilder();
+ result.append(new Timestamp(record.getMillis()));
+ result.append(" "); //$NON-NLS-1$
+ result.append(record.getLoggerName());
+ result.append(" "); //$NON-NLS-1$
+ result.append(record.getLevel());
+ result.append(" "); //$NON-NLS-1$
+ result.append(record.getThreadID());
+ result.append(" "); //$NON-NLS-1$
+ result.append(record.getMessage());
+ result.append('\n');
+ if (record.getThrown() != null) {
+ record.getThrown().printStackTrace(new PrintWriter(new Writer() {
+ @Override
+ public void close() throws IOException {
+
+ }
+
+ @Override
+ public void flush() throws IOException {
+
+ }
+
+ @Override
+ public void write(char[] cbuf, int off, int len)
+ throws IOException {
+ result.append(new String(cbuf, off, len));
+ }
+ }));
+ result.append('\n');
+ }
+ return result.toString();
+ }
+ });
+ ch.setLevel(Level.FINEST);
+ logger.addHandler(ch);
+ }
+ }
+
}
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/Cache.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/Cache.java 2011-09-23 04:11:11 UTC (rev 3503)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/Cache.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -30,9 +30,9 @@
* Represents the storage strategy for the {@link BufferManager}
*/
public interface Cache extends StorageManager {
- void createCacheGroup(Long gid);
+ void createCacheGroup(Long gid); //called prior to adding an entry
Collection<Long> removeCacheGroup(Long gid);
- void addToCacheGroup(Long gid, Long oid); //called prior to adding an entry
+ void addToCacheGroup(Long gid, Long oid);
CacheEntry get(Long id, Serializer<?> serializer) throws TeiidComponentException;
void add(CacheEntry entry, Serializer<?> s);
void remove(Long gid, Long id);
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/FileStore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/FileStore.java 2011-09-23 04:11:11 UTC (rev 3503)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/FileStore.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -25,6 +25,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -223,6 +224,28 @@
};
}
+ public ByteBuffer getBuffer(long start, int length, boolean allocate) throws IOException {
+ byte[] b = new byte[length];
+ if (!allocate) {
+ readFully(start, b, 0, length);
+ }
+ return ByteBuffer.wrap(b);
+ }
+
+ public void updateFromBuffer(ByteBuffer bb, long start) throws IOException {
+ byte[] b = null;
+ int offset = 0;
+ bb.rewind();
+ if (bb.hasArray()) {
+ b = bb.array();
+ offset = bb.arrayOffset();
+ } else {
+ b = new byte[bb.limit()];
+ bb.get(b);
+ }
+ write(start, b, offset, bb.limit());
+ }
+
public InputStream createInputStream(final long start) {
return createInputStream(start, -1);
}
@@ -242,7 +265,7 @@
};
}
- public FileStoreOutputStream createOutputStream(int maxMemorySize) {
+ public FileStoreOutputStream createOutputStream(int maxMemorySize) {
return new FileStoreOutputStream(maxMemorySize);
}
Deleted: trunk/engine/src/main/java/org/teiid/common/buffer/impl/BitSetTree.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/BitSetTree.java 2011-09-23 04:11:11 UTC (rev 3503)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/BitSetTree.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -1,106 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library 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 library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
- package org.teiid.common.buffer.impl;
-
-import java.util.BitSet;
-
-/**
- * Extends a {@link BitSet} by adding a cumulative total and a
- * first level index to speed queries against large bitsets.
- */
-public class BitSetTree {
-
- public static final int MAX_INDEX = (1 << 24) - 1;
-
- private int bitsSet;
- private int totalBits;
- private short[] topVals = new short[1 << 9];
- private BitSet bitSet = new BitSet();
-
- public boolean get(int index) {
- if (index > MAX_INDEX) {
- throw new ArrayIndexOutOfBoundsException(index);
- }
- return bitSet.get(index);
- }
-
- /**
- * Set the given bit at the index. It's expected that the
- * bit currently has the opposite value.
- * @param bitIndex
- * @param value
- */
- public void set(int bitIndex, boolean value) {
- if (bitIndex > MAX_INDEX) {
- throw new ArrayIndexOutOfBoundsException(bitIndex);
- }
- bitSet.set(bitIndex, value);
- if (bitIndex >= totalBits) {
- totalBits = bitIndex + 1;
- }
- int topIndex = bitIndex >>> 15;
- int increment = value?1:-1;
- bitsSet+=increment;
- topVals[topIndex]+=increment;
- }
-
- public int getTotalBits() {
- return totalBits;
- }
-
- public int getBitsSet() {
- return bitsSet;
- }
-
- public int nextClearBit(int fromIndex) {
- int start = fromIndex >> 15;
- for (int i = start; i < topVals.length; i++) {
- if (topVals[i] < Short.MAX_VALUE) {
- int searchFrom = fromIndex;
- if (i > start) {
- searchFrom = i << 15;
- }
- return bitSet.nextClearBit(searchFrom);
- }
- }
- return -1;
- }
-
- public int nextSetBit(int fromIndex) {
- if (bitsSet == 0) {
- return -1;
- }
- int start = fromIndex >> 15;
- for (int i = fromIndex >> 15; i < topVals.length; i++) {
- if (topVals[i] > 0) {
- int searchFrom = fromIndex;
- if (i > start) {
- searchFrom = i << 15;
- }
- return bitSet.nextSetBit(searchFrom);
- }
- }
- return -1;
- }
-
-}
Added: trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockBitSetTree.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockBitSetTree.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockBitSetTree.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -0,0 +1,191 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+ package org.teiid.common.buffer.impl;
+
+import java.util.BitSet;
+
+import org.teiid.common.buffer.impl.FileStoreCache.BlockInfo;
+
+/**
+ * Extends a {@link BitSet} by adding a cumulative total and a
+ * first level index to speed queries against large bitsets.
+ */
+public class BlockBitSetTree {
+
+ private static final int LOG_BITS_PER_BLOCK = FileStoreCache.LOG_BLOCK_SIZE + 3;
+ private static final int MAX_TOP_VALUE = 1 << LOG_BITS_PER_BLOCK;
+ private int maxIndex;
+ private int bitsSet;
+ private int[] topVals;
+ private BlockManager blockManager;
+ private int blockCount = 0;
+
+ public BlockBitSetTree(int maxIndex, BlockManager blockManager) {
+ this.maxIndex = maxIndex;
+ this.blockManager = blockManager;
+ this.topVals = new int[(maxIndex >> (FileStoreCache.LOG_BLOCK_SIZE + 3)) + 1];
+ }
+
+ public int getMaxIndex() {
+ return maxIndex;
+ }
+
+ /**
+ * Set the given bit at the index.
+ * @param bitIndex
+ * @param value
+ */
+ public synchronized void set(int bitIndex, boolean value) {
+ getOrSet(bitIndex, value, true);
+ }
+
+ public synchronized boolean get(int bitIndex) {
+ return getOrSet(bitIndex, false, false);
+ }
+
+ private boolean getOrSet(int bitIndex, boolean value, boolean update) {
+ if (bitIndex > maxIndex) {
+ throw new ArrayIndexOutOfBoundsException(bitIndex);
+ }
+ int blockIndex = bitIndex>>LOG_BITS_PER_BLOCK;
+ BlockInfo bb = null;
+ if (blockIndex >= blockCount) {
+ if (!update) {
+ return false;
+ }
+ for (; blockCount < blockIndex+1; blockCount++) {
+ bb = blockManager.allocateBlock(blockCount);
+ bb.buf.position(0);
+ int longsPerBlock = FileStoreCache.BLOCK_SIZE >> 6;
+ for (int j = 0; j < longsPerBlock; j++) {
+ bb.buf.putLong(0);
+ }
+ }
+ } else {
+ bb = blockManager.getBlock(blockIndex);
+ }
+ int relativeIndex = bitIndex&(MAX_TOP_VALUE-1);
+ int longByteIndex = (relativeIndex>>6)<<3;
+ long word = bb.buf.getLong(longByteIndex);
+ long mask = 1L << bitIndex;
+ boolean currentValue = ((word & mask) != 0);
+ if (!update) {
+ return currentValue;
+ }
+ if (currentValue == value) {
+ return currentValue;
+ }
+ if (value) {
+ word |= mask;
+ } else {
+ word &= ~mask;
+ }
+ bb.buf.putLong(longByteIndex, word);
+ blockManager.updateBlock(bb);
+ int topIndex = bitIndex >> LOG_BITS_PER_BLOCK;
+ int increment = value?1:-1;
+ bitsSet+=increment;
+ topVals[topIndex]+=increment;
+ return currentValue;
+ }
+
+ public synchronized int getBitsSet() {
+ return bitsSet;
+ }
+
+ public synchronized int nextClearBit(int fromIndex) {
+ int start = fromIndex >> LOG_BITS_PER_BLOCK;
+ for (int i = start; i < topVals.length; i++) {
+ if (topVals[i] == MAX_TOP_VALUE) {
+ continue;
+ }
+ if (topVals[i] == 0) {
+ if (i == start) {
+ return fromIndex;
+ }
+ return i * MAX_TOP_VALUE;
+ }
+ int relativeIndex = 0;
+ if (i == start) {
+ relativeIndex = fromIndex&(MAX_TOP_VALUE-1);
+ }
+ BlockInfo bb = blockManager.getBlock(i);
+
+ int longByteIndex = (relativeIndex>>6)<<3;
+
+ long word = ~bb.buf.getLong(longByteIndex) & (-1l << relativeIndex);
+
+ while (true) {
+ if (word != 0) {
+ return longByteIndex*8 + (i * MAX_TOP_VALUE) + Long.numberOfTrailingZeros(word);
+ }
+ longByteIndex+=8;
+ if (longByteIndex > FileStoreCache.BLOCK_MASK) {
+ break;
+ }
+ word = ~bb.buf.getLong(longByteIndex);
+ }
+ }
+ return -1;
+ }
+
+ public synchronized int nextSetBit(int fromIndex) {
+ if (bitsSet == 0) {
+ return -1;
+ }
+ int start = fromIndex >> LOG_BITS_PER_BLOCK;
+ for (int i = start; i < topVals.length; i++) {
+ if (topVals[i] == 0) {
+ continue;
+ }
+ if (topVals[i] == MAX_TOP_VALUE) {
+ if (i == start) {
+ return fromIndex;
+ }
+ return i * MAX_TOP_VALUE;
+ }
+ int relativeIndex = 0;
+ if (i == start) {
+ relativeIndex = fromIndex&(MAX_TOP_VALUE-1);
+ }
+ BlockInfo bb = blockManager.getBlock(i);
+
+ int longByteIndex = (relativeIndex>>6)<<3;
+
+ long word = bb.buf.getLong(longByteIndex) & (-1l << relativeIndex);
+
+ while (true) {
+ if (word != 0) {
+ return longByteIndex*8 + (i * MAX_TOP_VALUE) + Long.numberOfTrailingZeros(word);
+ }
+ longByteIndex+=8;
+ if (longByteIndex > FileStoreCache.BLOCK_MASK) {
+ break;
+ }
+ word = bb.buf.getLong(longByteIndex);
+ }
+ }
+ return -1;
+ }
+
+}
Property changes on: trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockBitSetTree.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockClosedLongIntHashTable.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockClosedLongIntHashTable.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockClosedLongIntHashTable.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -0,0 +1,238 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer.impl;
+
+import java.nio.ByteBuffer;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.teiid.common.buffer.impl.FileStoreCache.BlockInfo;
+
+/**
+ * Represents the logical structure of a cache group / directory
+ *
+ * Implemented by a closed hash table using a single step linear probe with delayed removal.
+ * Uses power of 2 hashing.
+ *
+ * Provides an extremely simple hash structure that rivals {@link HashMap} performance and
+ * is directly mapped to {@link ByteBuffer}s to avoid serialization overhead.
+ *
+ * Does not expect keys or values to be negative.
+ */
+public class BlockClosedLongIntHashTable {
+
+ private enum Mode {
+ GET,
+ UPDATE,
+ REMOVE
+ }
+
+ private static final int BYTES_PER_ROW = 12; //8+4
+ private static final int BLOCK_SIZE = FileStoreCache.BLOCK_DATA_BYTES/BYTES_PER_ROW;
+ private static final float LOAD_FACTOR = .7f;
+ private static final int MIN_SIZE = 1 << (31 - Integer.numberOfLeadingZeros(BLOCK_SIZE)); //should fit in a single block
+
+ static final int EMPTY = -1;
+ private static final int REMOVED = -2;
+
+ protected int size;
+ protected int capacityMask = EMPTY;
+ protected BlockManager blockManager;
+
+ public BlockClosedLongIntHashTable(BlockManager blockManager) {
+ this.blockManager = blockManager;
+ }
+
+ private void init(int capacity) {
+ int currentBlockCount = blockCount(capacityMask + 1);
+ int desiredBlockCount = blockCount(capacity);
+ if (capacity > capacityMask) {
+ for (int i = currentBlockCount; i < desiredBlockCount; i++) {
+ BlockInfo bb = blockManager.allocateBlock(i);
+ empty(bb.buf, BLOCK_SIZE);
+ blockManager.updateBlock(bb);
+ }
+ }
+ capacityMask = capacity - 1;
+ }
+
+ private void empty(ByteBuffer bb, int toIndex) {
+ bb.position(0);
+ for (int j = 0; j < toIndex; j++) {
+ bb.putLong(j * BYTES_PER_ROW, EMPTY);
+ }
+ }
+
+ private static int blockCount(int size) {
+ int currentBlockCount = (size) / BLOCK_SIZE;
+ if (size%BLOCK_SIZE > 0) {
+ currentBlockCount++;
+ }
+ return currentBlockCount;
+ }
+
+ public synchronized int put(long key, int value) {
+ int result = getOrUpdate(key, value, Mode.UPDATE);
+ if ((result == EMPTY || result == REMOVED) && ++size > LOAD_FACTOR*capacityMask) {
+ int newCapacity = (capacityMask+1)<<1;
+ int oldLength = capacityMask + 1;
+ init(newCapacity);
+ rehash(oldLength, newCapacity);
+ }
+ return result;
+ }
+
+ public synchronized int get(long key) {
+ return getOrUpdate(key, EMPTY, Mode.GET);
+ }
+
+ public synchronized int remove(long key) {
+ int result = getOrUpdate(key, EMPTY, Mode.REMOVE);
+ if (result != EMPTY && --size*LOAD_FACTOR < capacityMask>>3 && (capacityMask+1)>>1 >= MIN_SIZE) {
+ //reduce the size of the table by half
+ int oldLength = capacityMask + 1;
+ capacityMask >>= 1;
+ rehash(oldLength, oldLength>>1);
+ int oldBlocks = blockCount(oldLength);
+ int newBlocks = blockCount(capacityMask +1);
+ for (int i = oldBlocks-1; i >= newBlocks; i--) {
+ blockManager.freeBlock(i);
+ }
+ }
+ return result;
+ }
+
+ private void rehash(int oldLength, int newLength) {
+ BlockInfo lastBlockInfo = null;
+ ByteBuffer lastBlock = null;
+ for (int i = 0; i < oldLength; i++) {
+ int relativeIndex = i%BLOCK_SIZE;
+ if (lastBlock == null || relativeIndex == 0) {
+ int lastIndex = i/BLOCK_SIZE;
+ lastBlockInfo = blockManager.getBlock(lastIndex);
+ lastBlock = lastBlockInfo.buf;
+ if (i < newLength) {
+ byte[] buf = new byte[FileStoreCache.BLOCK_DATA_BYTES];
+ lastBlock.position(0);
+ lastBlock.get(buf);
+ ByteBuffer copyBlock = ByteBuffer.wrap(buf);
+ empty(lastBlock, Math.min(BLOCK_SIZE, oldLength - lastIndex*BLOCK_SIZE));
+ blockManager.updateBlock(lastBlockInfo);
+ lastBlock = copyBlock;
+ }
+ }
+ lastBlock.position(relativeIndex*BYTES_PER_ROW);
+ long oldKey = lastBlock.getLong();
+ int oldValue = lastBlock.getInt();
+ if (oldKey != REMOVED && oldKey != EMPTY) {
+ getOrUpdate(oldKey, oldValue, Mode.UPDATE);
+ }
+ }
+ }
+
+ @SuppressWarnings("null")
+ protected int getOrUpdate(long key, int value, Mode mode) {
+ if (capacityMask == EMPTY) {
+ if (mode == Mode.GET || mode == Mode.REMOVE) {
+ return EMPTY;
+ }
+ init(MIN_SIZE);
+ }
+ int i = hashIndex(key);
+ BlockInfo lastBlockInfo = null;
+ long old = EMPTY;
+ int position = 0;
+ while (true) {
+ int relativeIndex = i%BLOCK_SIZE;
+ if (lastBlockInfo == null || relativeIndex == 0) {
+ int index = i/BLOCK_SIZE;
+ lastBlockInfo = blockManager.getBlock(index);
+ }
+ position = relativeIndex*BYTES_PER_ROW;
+ old = lastBlockInfo.buf.getLong(position);
+ if (old == EMPTY || old == key || (mode == Mode.UPDATE && old == REMOVED)) {
+ break;
+ }
+ i = (i + 1) & capacityMask;
+ }
+ int result = EMPTY;
+ if (old != EMPTY && old != REMOVED) {
+ result = lastBlockInfo.buf.getInt(position + 8);
+ }
+ switch (mode) {
+ case GET:
+ return result;
+ case UPDATE:
+ lastBlockInfo.buf.putLong(position, key);
+ lastBlockInfo.buf.putInt(position + 8, value);
+ blockManager.updateBlock(lastBlockInfo);
+ return result;
+ case REMOVE:
+ if (old == EMPTY || old == REMOVED) {
+ return EMPTY;
+ }
+ lastBlockInfo.buf.putLong(position, REMOVED);
+ blockManager.updateBlock(lastBlockInfo);
+ return result;
+ default:
+ throw new AssertionError();
+ }
+ }
+
+ private int hashIndex(long key) {
+ //start with the usual long hash
+ int primaryHash = (int)(key ^ (key >>> 32));
+ //allow the lower bits to spread the entries
+ primaryHash += primaryHash <<= 2;
+ primaryHash += primaryHash <<= 3;
+ return primaryHash & capacityMask;
+ }
+
+ public synchronized int size() {
+ return size;
+ }
+
+ public synchronized Map<Long, Integer> remove() {
+ Map<Long, Integer> result = new HashMap<Long, Integer>();
+ BlockInfo lastBlockInfo = null;
+ int blockIndex = 0;
+ for (int i = capacityMask; i >= 0; i--) {
+ int relativeIndex = i%BLOCK_SIZE;
+ if (lastBlockInfo == null || relativeIndex == BLOCK_SIZE - 1) {
+ if (lastBlockInfo != null) {
+ blockManager.freeBlock(blockIndex);
+ }
+ blockIndex = i/BLOCK_SIZE;
+ lastBlockInfo = blockManager.getBlock(blockIndex);
+ }
+ lastBlockInfo.buf.position(relativeIndex*BYTES_PER_ROW);
+ long key = lastBlockInfo.buf.getLong();
+ if (key != EMPTY && key != REMOVED) {
+ result.put(key, lastBlockInfo.buf.getInt());
+ }
+ }
+ blockManager.free();
+ return result;
+ }
+
+}
Property changes on: trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockClosedLongIntHashTable.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockManager.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockManager.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer.impl;
+
+import org.teiid.common.buffer.impl.FileStoreCache.BlockInfo;
+
+/**
+ * Represents an INode
+ *
+ * Returned BlockInfo may be shared. If shared there and no guarantees about position and mark.
+ * in particular system/index blocks can be used by multiple threads relative methods should be
+ * avoided, but may be used for exclusive write operations.
+ * Otherwise the position will be 0.
+ *
+ * Due to buffermanager locking, non-index data blocks can be assumed to be thread-safe.
+ */
+public interface BlockManager {
+
+ int getInode();
+
+ BlockInfo allocateBlock(int index);
+
+ BlockInfo getBlock(int index);
+
+ void updateBlock(BlockInfo block);
+
+ void freeBlock(int index);
+
+ void free();
+
+}
Property changes on: trunk/engine/src/main/java/org/teiid/common/buffer/impl/BlockManager.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java 2011-09-23 04:11:11 UTC (rev 3503)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -31,6 +31,7 @@
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
@@ -250,6 +251,7 @@
private boolean useWeakReferences = true;
private boolean inlineLobs = true;
private int targetBytesPerRow = TARGET_BYTES_PER_ROW;
+ private int maxSoftReferences;
private ReentrantLock lock = new ReentrantLock(true);
private Condition batchesFreed = lock.newCondition();
@@ -260,10 +262,23 @@
private LinkedHashMap<Long, CacheEntry> memoryEntries = new LinkedHashMap<Long, CacheEntry>(16, .75f, false);
private LinkedHashMap<Long, CacheEntry> tenuredMemoryEntries = new LinkedHashMap<Long, CacheEntry>(16, .75f, true);
- private WeakReferenceHashedValueCache<CacheEntry> weakReferenceCache; //limited size based upon the memory settings
- private ConcurrentHashMap<Long, BatchSoftReference> softCache = new ConcurrentHashMap<Long, BatchSoftReference>(); //"unlimitted" size maintained by reference queue
+ //limited size reference caches based upon the memory settings
+ private WeakReferenceHashedValueCache<CacheEntry> weakReferenceCache;
+ private Map<Long, BatchSoftReference> softCache = Collections.synchronizedMap(new LinkedHashMap<Long, BatchSoftReference>(16, .75f, false) {
+ private static final long serialVersionUID = 1L;
+
+ protected boolean removeEldestEntry(Map.Entry<Long,BatchSoftReference> eldest) {
+ if (size() > maxSoftReferences) {
+ BatchSoftReference bsr = eldest.getValue();
+ maxReserveKB.addAndGet(bsr.sizeEstimate);
+ bsr.clear();
+ return true;
+ }
+ return false;
+ };
+ });
- private Cache cache;
+ Cache cache;
private Map<String, TupleReference> tupleBufferMap = new ConcurrentHashMap<String, TupleReference>();
private ReferenceQueue<TupleBuffer> tupleBufferQueue = new ReferenceQueue<TupleBuffer>();
@@ -430,11 +445,12 @@
if (this.maxProcessingKBOrig < 0) {
this.maxProcessingKB = Math.max(Math.min(8 * processorBatchSize, Integer.MAX_VALUE), (int)(.1 * maxMemory)/maxActivePlans);
}
+ int memoryBatches = (this.maxProcessingKB * maxActivePlans + this.getMaxReserveKB()) / (processorBatchSize * targetBytesPerRow / 1024);
+ int logSize = 39 - Integer.numberOfLeadingZeros(memoryBatches);
if (useWeakReferences) {
- int memoryBatches = (this.maxProcessingKB * maxActivePlans + this.getMaxReserveKB()) / (processorBatchSize * targetBytesPerRow / 1024);
- int logSize = 39 - Integer.numberOfLeadingZeros(memoryBatches);
weakReferenceCache = new WeakReferenceHashedValueCache<CacheEntry>(Math.min(20, logSize));
}
+ this.maxSoftReferences = 1 << Math.max(28, logSize+2);
}
@Override
@@ -551,7 +567,7 @@
}
private void createSoftReference(CacheEntry ce) {
- BatchSoftReference ref = new BatchSoftReference(ce, SOFT_QUEUE, ce.getSizeEstimate());
+ BatchSoftReference ref = new BatchSoftReference(ce, SOFT_QUEUE, ce.getSizeEstimate()/2);
softCache.put(ce.getId(), ref);
maxReserveKB.addAndGet(- ce.getSizeEstimate()/2);
}
@@ -584,12 +600,11 @@
return ce;
}
if (prefersMemory) {
- BatchSoftReference bsr = softCache.get(batch);
+ BatchSoftReference bsr = softCache.remove(batch);
if (bsr != null) {
ce = bsr.get();
if (ce != null) {
- softCache.remove(batch);
- maxReserveKB.addAndGet(bsr.sizeEstimate/2);
+ maxReserveKB.addAndGet(bsr.sizeEstimate);
}
}
} else if (useWeakReferences) {
@@ -611,6 +626,9 @@
}
void remove(Long gid, Long batch, boolean prefersMemory) {
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
+ LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "Removing batch from BufferManager", batch); //$NON-NLS-1$
+ }
CacheEntry ce = fastGet(batch, prefersMemory, false);
if (ce == null) {
cache.remove(gid, batch);
@@ -661,8 +679,7 @@
break;
}
softCache.remove(ref.key);
- maxReserveKB.addAndGet(ref.sizeEstimate/2);
- ref.sizeEstimate = 0;
+ maxReserveKB.addAndGet(ref.sizeEstimate);
ref.clear();
}
}
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/ExtensibleBufferedOutputStream.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/ExtensibleBufferedOutputStream.java 2011-09-23 04:11:11 UTC (rev 3503)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/ExtensibleBufferedOutputStream.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -24,32 +24,37 @@
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.ByteBuffer;
public abstract class ExtensibleBufferedOutputStream extends OutputStream {
- protected int bytesWritten;
- protected byte buf[];
- protected int count;
+ protected ByteBuffer buf;
- public ExtensibleBufferedOutputStream(byte[] buf) {
- this.buf = buf;
+ public ExtensibleBufferedOutputStream() {
}
public void write(int b) throws IOException {
- if (count >= buf.length) {
+ ensureBuffer();
+ if (buf.remaining() == 0) {
flush();
}
- buf[count++] = (byte)b;
+ buf.put((byte)b);
}
+ private void ensureBuffer() {
+ if (buf == null) {
+ buf = newBuffer();
+ }
+ }
+
public void write(byte b[], int off, int len) throws IOException {
while (true) {
- int toCopy = Math.min(buf.length - count, len);
- System.arraycopy(b, off, buf, count, toCopy);
- count += toCopy;
+ ensureBuffer();
+ int toCopy = Math.min(buf.remaining(), len);
+ buf.put(b, off, toCopy);
len -= toCopy;
off += toCopy;
- if (count < buf.length) {
+ if (buf.remaining() > 0) {
break;
}
flush();
@@ -57,12 +62,13 @@
}
public void flush() throws IOException {
- if (count > 0) {
+ if (buf != null && buf.position() > 0) {
flushDirect();
}
- bytesWritten += count;
- count = 0;
+ buf = null;
}
+
+ protected abstract ByteBuffer newBuffer();
protected abstract void flushDirect() throws IOException;
@@ -71,8 +77,4 @@
flush();
}
- public int getBytesWritten() {
- return bytesWritten;
- }
-
}
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStorageManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStorageManager.java 2011-09-23 04:11:11 UTC (rev 3503)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStorageManager.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -151,6 +151,9 @@
@Override
public synchronized void setLength(long length) throws IOException {
+ if (fileInfo == null) {
+ fileInfo = new FileInfo(createFile(name));
+ }
try {
fileInfo.open().setLength(length);
} finally {
@@ -165,7 +168,7 @@
fileInfo.delete();
}
}
-
+
}
// Initialization
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStoreCache.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStoreCache.java 2011-09-23 04:11:11 UTC (rev 3503)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStoreCache.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -27,15 +27,12 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.nio.ByteBuffer;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
+import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.concurrent.locks.ReentrantLock;
import org.teiid.common.buffer.Cache;
import org.teiid.common.buffer.CacheEntry;
@@ -50,298 +47,604 @@
import org.teiid.query.QueryPlugin;
/**
- * Implements storage and caching against a {@link FileStore} abstraction.
- * caching uses a block paradigm, where the first block has the format
- * long gid | long oid | short tail bytes | short sector table length | [3 byte int sector ...]
- *
- * TODO: back non-fragmented block information onto the block address
+ * Implements storage against a {@link FileStore} abstraction using a filesystem paradigm.
+ * The filesystem uses a 31bit address space on top of 2^14 byte blocks.
+ *
+ * Therefore there is 2^31*2^14 = 2^45 or 32 terabytes max of addressable space.
+ *
+ * Some amount of the space is taken up by system information (inodes and use flags).
+ * This is held in a separate file.
+ *
+ * The 64 byte inode format is:
+ * 14 32 bit direct block pointers
+ * 1 32 bit block indirect pointer
+ * 1 32 bit block doubly indirect pointer
+ *
+ * The data block format is:
+ * data bytes | long gid | long oid | three byte int block num
+ *
+ * The gid/oid are stored with the block so that defrag/compaction can be performed
+ * with minimal blocking/lookups.
+ *
+ * This means that the maximum number of blocks available to a "file" is
+ * 14 + (2^14-18)/4 + ((2^14-18)/4)^2 ~= 2^24
+ *
+ * Thus the max serialized object size is: 2^24*(2^14-18) ~= 256GB.
+ *
+ * The root directory "physicalMapping" is held in memory for performance,
+ * but could itself be switched to using a block map. It will grow in
+ * proportion to the number of tables/tuplebuffers in use.
+ *
+ * TODO: defragment
+ * TODO: lobs could also be supported in this structure.
*/
public class FileStoreCache implements Cache, StorageManager {
- private static final int IO_BUFFER_SIZE = 1 << 14;
- private static final int DATA_START = 1 << 13;
- private static final int MAX_BLOCKS = 2724; //implies that the max size is ~ 42.5 mb
+ //TODO allow the block size to be configurable
+ static final int LOG_BLOCK_SIZE = 14;
+ static final int ADDRESS_BITS = 31;
+ static final int SYSTEM_MASK = 1<<ADDRESS_BITS;
+ static final int BLOCK_SIZE = 1 << LOG_BLOCK_SIZE;
+ static final int BLOCK_MASK = BLOCK_SIZE - 1;
+ static final int BLOCK_OVERHEAD = 8+8+3;
+ static final int BLOCK_DATA_BYTES = BLOCK_SIZE - BLOCK_OVERHEAD;
+ static final int BYTES_PER_BLOCK_ADDRESS = 4;
+ static final int ADDRESSES_PER_BLOCK = BLOCK_DATA_BYTES/BYTES_PER_BLOCK_ADDRESS;
+ static final int INODE_BYTES = 16*BYTES_PER_BLOCK_ADDRESS;
+ static final int DIRECT_POINTERS = 14;
+ static final int MAX_INDIRECT = DIRECT_POINTERS + ADDRESSES_PER_BLOCK;
+ static final int MAX_DOUBLE_INDIRECT = MAX_INDIRECT + ADDRESSES_PER_BLOCK * ADDRESSES_PER_BLOCK;
+ static final int EMPTY_ADDRESS = -1;
+
+ private final class BlockOutputStream extends
+ ExtensibleBufferedOutputStream {
+ private final BlockManager blockManager;
+ int blockNum = -1;
+ BlockInfo bi;
+
+ private BlockOutputStream(BlockManager blockManager) {
+ this.blockManager = blockManager;
+ }
+
+ @Override
+ protected ByteBuffer newBuffer() {
+ bi = blockManager.allocateBlock(++blockNum);
+ return bi.buf;
+ }
+
+ @Override
+ protected void flushDirect() throws IOException {
+ blockManager.updateBlock(bi);
+ bi = null;
+ }
+ }
+
+ private final class BitSetBlockManager implements BlockManager {
+ final int offset;
+
+ BitSetBlockManager(int offset) {
+ this.offset = offset;
+ }
+
+ @Override
+ public void updateBlock(BlockInfo info) {
+ updatePhysicalBlock(info);
+ }
+
+ @Override
+ public BlockInfo getBlock(int index) {
+ return getPhysicalBlock(index + offset, true, false);
+ }
+
+ @Override
+ public BlockInfo allocateBlock(int index) {
+ return getPhysicalBlock(index + offset, true, true);
+ }
+
+ @Override
+ public int getInode() {
+ throw new AssertionError();
+ }
+
+ @Override
+ public void freeBlock(int index) {
+ throw new AssertionError();
+ }
+
+ @Override
+ public void free() {
+ throw new AssertionError();
+ }
+
+ }
- static class TryFreeParameter {
- Long gid;
- Long oid;
- Integer block;
+ private enum Mode {
+ GET,
+ UPDATE,
+ ALLOCATE
+ }
+
+ static final class BlockInfo {
+ final boolean system;
+ final int inodeOffset;
+ final ByteBuffer buf;
+ final int physicalAddress;
+ boolean dirty;
+
+ BlockInfo(boolean system, ByteBuffer ib, int index, int inodeOffset) {
+ this.system = system;
+ this.buf = ib;
+ this.physicalAddress = index;
+ this.inodeOffset = inodeOffset;
+ }
+ }
+
+ private final class InodeBlockManager implements BlockManager {
+ private final int inode;
+ private final long gid;
+ private final long oid;
+ private int lastBlock = -1;
+ boolean trackLast;
- public TryFreeParameter(Long gid, Long oid, Integer block) {
+ InodeBlockManager(long gid, long oid, int inode) {
+ if (inode == EMPTY_ADDRESS) {
+ synchronized (inodesInuse) {
+ inode = inodesInuse.nextClearBit(0);
+ if (inode == -1) {
+ throw new TeiidRuntimeException("no inodes available"); //$NON-NLS-1$
+ }
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.TRACE)) {
+ LogManager.logTrace(LogConstants.CTX_DQP, "Allocating inode", inode, "to", gid, oid); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ inodesInuse.set(inode, true);
+ }
+ int inodeBlock = inode/inodesPerBlock;
+ int inodePosition = INODE_BYTES*(inode%inodesPerBlock);
+ BlockInfo bb = getInodeSubBlock(inodeBlock, inodePosition);
+ bb.buf.putInt(EMPTY_ADDRESS);
+ updatePhysicalBlock(bb);
+ }
+ this.inode = inode;
this.gid = gid;
this.oid = oid;
- this.block = block;
}
- }
-
- private class Segment {
- int id;
- ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
- List<TryFreeParameter> freed = Collections.synchronizedList(new ArrayList<TryFreeParameter>());
- FileStore store;
- BitSetTree inuse = new BitSetTree();
- BitSetTree fragmentedFlags = new BitSetTree();
- public Segment(int id) {
- this.id = id;
+ @Override
+ public int getInode() {
+ return inode;
}
-
- void tryFree(Long gid, Long oid, Integer block) {
- if (lock.writeLock().tryLock()) {
- try {
- free(gid, oid, block);
- } finally {
- lock.writeLock().unlock();
+
+ @Override
+ public void updateBlock(BlockInfo info) {
+ updatePhysicalBlock(info);
+ }
+
+ @Override
+ public BlockInfo getBlock(int index) {
+ int dataBlock = getOrUpdateDataBlockIndex(index, EMPTY_ADDRESS, Mode.GET);
+ BlockInfo bb = getPhysicalBlock(dataBlock, false, false);
+ bb.buf.position(0);
+ bb.buf.limit(BLOCK_DATA_BYTES);
+ return bb;
+ }
+
+ private int getOrUpdateDataBlockIndex(int index, int value, Mode mode) {
+ if (index >= MAX_DOUBLE_INDIRECT) {
+ throw new TeiidRuntimeException("Max block number exceeded"); //$NON-NLS-1$
+ }
+ int dataBlock = 0;
+ int position = 0;
+ int inodePosition = INODE_BYTES*(inode%inodesPerBlock);
+ BlockInfo info = getInodeSubBlock(inode/inodesPerBlock, inodePosition);
+ if (index >= MAX_INDIRECT) {
+ position = BYTES_PER_BLOCK_ADDRESS*(DIRECT_POINTERS+1);
+ BlockInfo next = updateIndirectBlockInfo(info, index, position, MAX_INDIRECT, MAX_DOUBLE_INDIRECT+1, value, mode);
+ if (next != info) {
+ info = next;
+ //should have traversed to the secondary
+ int indirectAddressBlock = (index - MAX_INDIRECT) / ADDRESSES_PER_BLOCK;
+ position = indirectAddressBlock * BYTES_PER_BLOCK_ADDRESS;
+ if (mode == Mode.ALLOCATE && position + BYTES_PER_BLOCK_ADDRESS < BLOCK_DATA_BYTES) {
+ info.buf.putInt(position + BYTES_PER_BLOCK_ADDRESS, EMPTY_ADDRESS);
+ }
+ next = updateIndirectBlockInfo(info, index, position, MAX_INDIRECT + indirectAddressBlock * ADDRESSES_PER_BLOCK, MAX_DOUBLE_INDIRECT + 2 + indirectAddressBlock, value, mode);
+ if (next != info) {
+ info = next;
+ position = ((index - MAX_INDIRECT)%ADDRESSES_PER_BLOCK) * BYTES_PER_BLOCK_ADDRESS;
+ if (mode == Mode.ALLOCATE && position + BYTES_PER_BLOCK_ADDRESS < BLOCK_DATA_BYTES) {
+ info.buf.putInt(position + BYTES_PER_BLOCK_ADDRESS, EMPTY_ADDRESS);
+ }
+ }
}
+ } else if (index >= DIRECT_POINTERS) {
+ //indirect
+ position = BYTES_PER_BLOCK_ADDRESS*DIRECT_POINTERS;
+ BlockInfo next = updateIndirectBlockInfo(info, index, position, DIRECT_POINTERS, MAX_DOUBLE_INDIRECT, value, mode);
+ if (next != info) {
+ info = next;
+ position = (index - DIRECT_POINTERS) * BYTES_PER_BLOCK_ADDRESS;
+ if (mode == Mode.ALLOCATE && position + BYTES_PER_BLOCK_ADDRESS < BLOCK_DATA_BYTES) {
+ info.buf.putInt(position + BYTES_PER_BLOCK_ADDRESS, EMPTY_ADDRESS);
+ }
+ }
} else {
- freed.add(new TryFreeParameter(gid, oid, block));
+ position = BYTES_PER_BLOCK_ADDRESS*index;
+ if (mode == Mode.ALLOCATE) {
+ info.buf.putInt(position + BYTES_PER_BLOCK_ADDRESS, EMPTY_ADDRESS);
+ }
}
+ if (mode == Mode.ALLOCATE) {
+ dataBlock = nextBlock();
+ info.buf.putInt(position, dataBlock);
+ updatePhysicalBlock(info);
+ } else {
+ dataBlock = info.buf.getInt(position);
+ if (mode == Mode.UPDATE) {
+ info.buf.putInt(position, value);
+ updatePhysicalBlock(info);
+ }
+ }
+ return dataBlock;
}
- private void free(Long gid, Long oid, Integer block) {
- if (block == null) {
- Map<Long, Integer> map = physicalMapping.get(gid);
- if (map == null) {
- return;
+ private BlockInfo updateIndirectBlockInfo(BlockInfo info, int index, int position, int cutOff, int blockId, int value, Mode mode) {
+ int sib_index = info.buf.getInt(position);
+ boolean newBlock = false;
+ if (index == cutOff) {
+ if (mode == Mode.ALLOCATE) {
+ sib_index = nextBlock();
+ info.buf.putInt(position, sib_index);
+ updatePhysicalBlock(info);
+ newBlock = true;
+ } else if (mode == Mode.UPDATE && value == EMPTY_ADDRESS) {
+ freeDataBlock(sib_index);
+ return info;
}
- block = map.remove(oid);
- if (block == null) {
- return;
+ }
+ info = getPhysicalBlock(sib_index, false, false);
+ if (newBlock) {
+ putBlockId(blockId, info.buf);
+ }
+ return info;
+ }
+
+ private int nextBlock() {
+ int next = -1;
+ synchronized (blocksInuse) {
+ next = blocksInuse.nextClearBit(lastBlock + 1);
+ if (next == -1) {
+ throw new TeiidRuntimeException("no freespace available"); //$NON-NLS-1$
}
+ blocksInuse.set(next, true);
}
- byte[] buf = new byte[DATA_START];
- try {
- inuse.set(block, false);
- boolean fragmented = false;
- if (fragmentedFlags.get(block)) {
- fragmented = true;
- store.read(block << 14, buf, 0, buf.length);
- fragmentedFlags.set(block, false);
- } else {
- //TODO: if not fragmented come up with a better approach than a disk read
- store.read(block << 14, buf, 0, 20);
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.TRACE)) {
+ LogManager.logTrace(LogConstants.CTX_DQP, "Allocating block", next, "to", gid, oid); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ if (trackLast) {
+ lastBlock = next;
+ }
+ return next;
+ }
+
+ @Override
+ public void freeBlock(int index) {
+ int dataBlock = getOrUpdateDataBlockIndex(index, EMPTY_ADDRESS, Mode.UPDATE);
+ freeDataBlock(dataBlock);
+ }
+
+ private void freeDataBlock(int dataBlock) {
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.TRACE)) {
+ LogManager.logTrace(LogConstants.CTX_DQP, "freeing data block", dataBlock, "for", gid, oid); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ blockCache.remove(dataBlock);
+ blocksInuse.set(dataBlock, false);
+ }
+
+ BlockInfo getInodeSubBlock(int inodeBlock, int inodePosition) {
+ BlockInfo bi = getPhysicalBlock(inodeBlock + blocksInUseBlocks + inodesInUseBlocks, true, false);
+ ByteBuffer bb = bi.buf.duplicate();
+ bb.position(inodePosition);
+ bb.limit(inodePosition + INODE_BYTES);
+ bb = bb.slice();
+ return new BlockInfo(true, bb, inodeBlock + blocksInUseBlocks + inodesInUseBlocks, inodePosition);
+ }
+
+ @Override
+ public void free() {
+ int inodeBlock = inode/inodesPerBlock;
+ int inodePosition = INODE_BYTES*(inode%inodesPerBlock);
+ BlockInfo bi = getInodeSubBlock(inodeBlock, inodePosition);
+ ByteBuffer ib = bi.buf;
+ int indirectIndexBlock = ib.getInt(ib.position() + BYTES_PER_BLOCK_ADDRESS*DIRECT_POINTERS);
+ int doublyIndirectIndexBlock = ib.getInt(ib.position() + BYTES_PER_BLOCK_ADDRESS*(DIRECT_POINTERS+1));
+ boolean freedAll = freeBlock(ib, DIRECT_POINTERS, true);
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.TRACE)) {
+ LogManager.logTrace(LogConstants.CTX_DQP, "freeing inode", inode, "for", gid, oid); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ inodesInuse.set(inode, false);
+ if (!freedAll || indirectIndexBlock == EMPTY_ADDRESS) {
+ return;
+ }
+ freedAll = freeIndirectBlock(indirectIndexBlock);
+ if (!freedAll || doublyIndirectIndexBlock == EMPTY_ADDRESS) {
+ return;
+ }
+ BlockInfo bb = getPhysicalBlock(doublyIndirectIndexBlock, false, false);
+ freeBlock(bb.buf, ADDRESSES_PER_BLOCK, false);
+ freeDataBlock(doublyIndirectIndexBlock);
+ }
+
+ private boolean freeIndirectBlock(int indirectIndexBlock) {
+ BlockInfo bb = getPhysicalBlock(indirectIndexBlock, false, false);
+ bb.buf.position(0);
+ boolean freedAll = freeBlock(bb.buf, ADDRESSES_PER_BLOCK, true);
+ freeDataBlock(indirectIndexBlock);
+ return freedAll;
+ }
+
+ private boolean freeBlock(ByteBuffer ib, int numPointers, boolean primary) {
+ for (int i = 0; i < numPointers; i++) {
+ int dataBlock = ib.getInt();
+ if (dataBlock == EMPTY_ADDRESS) {
+ return false;
}
- ByteBuffer bb = ByteBuffer.wrap(buf);
- bb.position(18);
- short blocks = bb.getShort();
- if (!fragmented) {
- for (int i = block + 1; i < blocks; i++) {
- inuse.set(i, false);
- }
+ if (primary) {
+ freeDataBlock(dataBlock);
} else {
- for (short i = 0; i < blocks; i++) {
- int toFree = getNextBlock(bb);
- inuse.set(toFree, false);
- }
+ freeIndirectBlock(dataBlock);
}
- } catch (IOException e) {
- throw new TeiidRuntimeException(e, "Could not read intial block to process freeing " + oid); //$NON-NLS-1$
}
+ return true;
}
- @SuppressWarnings("unchecked")
- void add(final CacheEntry entry, final Serializer s) throws TeiidComponentException {
- lock.writeLock().lock();
+ @Override
+ public BlockInfo allocateBlock(int blockNum) {
+ int dataBlock = getOrUpdateDataBlockIndex(blockNum, EMPTY_ADDRESS, Mode.ALLOCATE);
+ BlockInfo bb = getPhysicalBlock(dataBlock, false, true);
+ putBlockId(blockNum, bb.buf);
+ bb.buf.position(0);
+ bb.buf.limit(BLOCK_DATA_BYTES);
+ return bb;
+ }
+
+ private void putBlockId(int blockNum, ByteBuffer bb) {
+ bb.position(BLOCK_DATA_BYTES);
+ bb.putLong(gid);
+ bb.putLong(oid);
+ bb.put((byte)(blockNum >> 16));
+ bb.putShort((short)blockNum);
+ }
+
+ }
+
+ private StorageManager storageManager;
+ private long maxBufferSpace = FileStorageManager.DEFAULT_MAX_BUFFERSPACE;
+ private int inodes;
+ private int blocks;
+ private int inodesPerBlock;
+ private int inodesInUseBlocks;
+ private int blocksInUseBlocks;
+ private FileStore store;
+ private FileStore systemStore;
+ private BlockBitSetTree blocksInuse;
+ private BlockBitSetTree inodesInuse;
+
+ //root directory
+ ConcurrentHashMap<Long, BlockClosedLongIntHashTable> physicalMapping = new ConcurrentHashMap<Long, BlockClosedLongIntHashTable>();
+
+ //block caching
+ int blockCacheSize = 128; //2 MB
+ ReentrantLock blockLock = new ReentrantLock();
+ LinkedHashMap<Integer, BlockInfo> blockCache = new LinkedHashMap<Integer, BlockInfo>() {
+ private static final long serialVersionUID = -4240291744435552008L;
+ BlockInfo eldestEntry = null;
+
+ protected boolean removeEldestEntry(Map.Entry<Integer,BlockInfo> eldest) {
+ if (size() > blockCacheSize) {
+ BlockInfo bi = eldest.getValue();
+ if (bi.dirty) {
+ eldestEntry = bi;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public BlockInfo put(Integer key, BlockInfo value) {
+ blockLock.lock();
+ value.dirty = true;
try {
- List<TryFreeParameter> toFree = Collections.emptyList();
- synchronized (freed) {
- if (!freed.isEmpty()) {
- toFree = new ArrayList<TryFreeParameter>(freed);
- freed.clear();
- }
+ return super.put(key, value);
+ } finally {
+ BlockInfo toUpdate = eldestEntry;
+ eldestEntry = null;
+ blockLock.unlock();
+ if (toUpdate != null) {
+ updatePhysicalBlockDirect(toUpdate);
}
- for (TryFreeParameter param : toFree) {
- free(param.gid, param.oid, param.block);
- }
- ExtensibleBufferedOutputStream fsos = new ExtensibleBufferedOutputStream(new byte[IO_BUFFER_SIZE]) {
-
- byte[] firstBytes = null;
- List<Integer> blocks = new ArrayList<Integer>(8);
- boolean isFragmented;
- int lastCount;
- int start;
-
- @Override
- protected void flushDirect() throws IOException {
- lastCount = count;
- if (firstBytes == null) {
- start = nextBlock(-1);
- firstBytes = buf;
- //need a new buffer only if there could be bytes remaining
- if (count == buf.length) {
- buf = new byte[IO_BUFFER_SIZE];
- }
- } else {
- int last = -1;
- if (!blocks.isEmpty()) {
- last = blocks.get(blocks.size()-1);
- } else {
- last = start;
- }
- int next = nextBlock(last);
- blocks.add(next);
- if (next != last + 1) {
- isFragmented = true;
- }
- if (blocks.size() > MAX_BLOCKS) {
- //TODO handle this case
- throw new TeiidRuntimeException("Exceeded max persistent object size" + entry.getId()); //$NON-NLS-1$
- }
- store.write(next << 14, buf, 0, count);
- }
- }
-
- @Override
- public void close() throws IOException {
- super.close();
- ByteBuffer bb = ByteBuffer.wrap(firstBytes);
- bb.putLong(s.getId());
- bb.putLong(entry.getId());
- bb.putShort((short)(lastCount - (blocks.isEmpty()?DATA_START:0)));
- bb.putShort((short)blocks.size());
- for (Integer i : blocks) {
- bb.put((byte)(i.intValue()>>16));
- bb.putShort((short)i.intValue());
- }
- store.write(start << 14, firstBytes, 0, firstBytes.length);
- if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
- LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, id, entry.getId(), "batch written starting at:", start); //$NON-NLS-1$
- }
- Map<Long, Integer> map = physicalMapping.get(s.getId());
- if (map == null) {
- return;
- }
- map.put(entry.getId(), start);
- inuse.set(start, true);
- for (Integer i : blocks) {
- inuse.set(i, true);
- }
- if (isFragmented) {
- fragmentedFlags.set(start, true);
- }
- }
-
- };
- fsos.count = DATA_START;
- ObjectOutputStream oos = new ObjectOutputStream(fsos);
- oos.writeInt(entry.getSizeEstimate());
- s.serialize(entry.getObject(), oos);
- oos.close();
- } catch (IOException e) {
- throw new TeiidComponentException(e);
- } finally {
- lock.writeLock().unlock();
}
-
- if (entry.getId().longValue() == 451) {
- get(entry.getId(), s);
- }
}
- int nextBlock(int fromIndex) {
- int next = inuse.nextClearBit(fromIndex + 1);
- if (next == -1) {
- throw new TeiidRuntimeException("no freespace available on segment" + id); //$NON-NLS-1$
+ public BlockInfo get(Object key) {
+ blockLock.lock();
+ try {
+ return super.get(key);
+ } finally {
+ blockLock.unlock();
}
- return next;
}
- @SuppressWarnings("unchecked")
- CacheEntry get(Long oid, Serializer serializer) throws TeiidComponentException {
- lock.readLock().lock();
+ public BlockInfo remove(Object key) {
+ blockLock.lock();
try {
- Map<Long, Integer> map = physicalMapping.get(serializer.getId());
- if (map == null) {
- return null;
+ return super.remove(key);
+ } finally {
+ blockLock.unlock();
+ }
+ }
+ };
+
+ BlockInfo getPhysicalBlock(int block, boolean system, boolean allocate) {
+ if (block < 0) {
+ throw new AssertionError("invalid block address " + block); //$NON-NLS-1$
+ }
+ try {
+ int key = block;
+ if (system) {
+ key |= SYSTEM_MASK;
+ }
+ BlockInfo result = blockCache.get(key);
+ assert result == null || !allocate;
+ if (result == null) {
+ ByteBuffer bb = null;
+ if (system) {
+ bb = systemStore.getBuffer(block<<LOG_BLOCK_SIZE, BLOCK_SIZE, allocate);
+ } else {
+ bb = store.getBuffer(block<<LOG_BLOCK_SIZE, BLOCK_SIZE, allocate);
}
- final Integer startBlock = map.get(oid);
- if (startBlock == null) {
- return null;
+ result = new BlockInfo(system, bb, block, -1);
+ blockLock.lock();
+ try {
+ BlockInfo existing = blockCache.get(key);
+ if (existing != null) {
+ return existing;
+ }
+ blockCache.put(key, result);
+ } finally {
+ blockLock.unlock();
}
- ObjectInputStream ois = new ObjectInputStream(new InputStream() {
-
- int count;
- int pos;
- byte[] buf = new byte[IO_BUFFER_SIZE];
- ByteBuffer firstBytes;
- int currentBlock;
- short tailBytes;
- short totalBlocks;
- short blockNum;
-
- @Override
- public int read() throws IOException {
- if (pos == count) {
- if (firstBytes == null) {
- store.readFully(startBlock << 14, buf, 0, buf.length);
- firstBytes = ByteBuffer.wrap(buf);
- firstBytes.position(16);
- tailBytes = firstBytes.getShort();
- totalBlocks = firstBytes.getShort();
- count = buf.length;
- pos = DATA_START;
- } else {
- buf = new byte[IO_BUFFER_SIZE];
- //TODO: defrag on read
- if (count == buf.length) {
- currentBlock = getNextBlock(firstBytes);
- blockNum++;
- pos = 0;
- }
- int length = blockNum == totalBlocks?tailBytes:buf.length;
- store.readFully(currentBlock << 14, buf, 0, length);
- count = length;
- }
- }
- return buf[pos++] & 0xff;
+ return result;
+ }
+ return result;
+ } catch (IOException e) {
+ throw new TeiidRuntimeException(e);
+ }
+ }
+
+ void updatePhysicalBlock(BlockInfo bi) {
+ int key = bi.physicalAddress;
+ if (bi.system) {
+ key |= SYSTEM_MASK;
+ }
+ if (bi.inodeOffset >= 0) {
+ blockLock.lock();
+ try {
+ BlockInfo actual = blockCache.get(key);
+ if (actual == null) {
+ //we're not in the cache, so just update storage
+ updatePhysicalBlockDirect(bi);
+ } else {
+ //TODO: check to see we're sharing the same buffer
+ for (int i = 0; i < INODE_BYTES; i++) {
+ actual.buf.put(bi.inodeOffset + i, bi.buf.get(i));
}
- });
- CacheEntry ce = new CacheEntry(oid);
- ce.setSizeEstimate(ois.readInt());
- ce.setObject(serializer.deserialize(ois));
- ce.setPersistent(true);
- return ce;
- } catch(IOException e) {
- throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", id)); //$NON-NLS-1$
- } catch (ClassNotFoundException e) {
- throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", id)); //$NON-NLS-1$
- } finally {
- lock.readLock().unlock();
- }
+ }
+ } finally {
+ blockLock.unlock();
+ }
+ return;
}
+ blockCache.put(key, bi);
}
+
+ private void updatePhysicalBlockDirect(BlockInfo bi) {
+ try {
+ bi.buf.rewind();
+ if (!bi.system) {
+ store.updateFromBuffer(bi.buf, bi.physicalAddress<<LOG_BLOCK_SIZE);
+ } else {
+ systemStore.updateFromBuffer(bi.buf, bi.physicalAddress<<LOG_BLOCK_SIZE);
+ }
+ } catch (IOException e) {
+ throw new TeiidRuntimeException(e);
+ }
+ }
- static int getNextBlock(ByteBuffer bb) {
- int block = (bb.get() & 0xff)<< 16;
- block += (bb.getShort() & 0xffff);
- return block;
+ InodeBlockManager getBlockManager(long gid, long oid, int inode) {
+ return new InodeBlockManager(gid, oid, inode);
}
-
- private StorageManager storageManager;
- private Segment[] segments;
- private ConcurrentHashMap<Long, Map<Long, Integer>> physicalMapping = new ConcurrentHashMap<Long, Map<Long,Integer>>();
- private int segmentCount = 32;
-
+
+ @SuppressWarnings("unchecked")
@Override
- public void add(CacheEntry entry, Serializer<?> s) {
- Segment seg = getSegment(entry.getId());
+ public void add(CacheEntry entry, Serializer s) {
+ boolean success = false;
+ InodeBlockManager blockManager = null;
try {
- seg.add(entry, s);
+ BlockClosedLongIntHashTable map = physicalMapping.get(s.getId());
+ if (map == null) {
+ return;
+ }
+ blockManager = getBlockManager(s.getId(), entry.getId(), EMPTY_ADDRESS);
+ blockManager.trackLast = true;
+ ExtensibleBufferedOutputStream fsos = new BlockOutputStream(blockManager);
+ ObjectOutputStream oos = new ObjectOutputStream(fsos);
+ oos.writeInt(entry.getSizeEstimate());
+ s.serialize(entry.getObject(), oos);
+ oos.close();
+ map.put(entry.getId(), blockManager.getInode());
+ success = true;
} catch (Throwable e) {
LogManager.logError(LogConstants.CTX_BUFFER_MGR, e, "Error persisting batch, attempts to read batch "+ entry.getId() +" later will result in an exception"); //$NON-NLS-1$ //$NON-NLS-2$
+ } finally {
+ if (!success && blockManager != null) {
+ blockManager.free();
+ }
}
}
-
+
@Override
- public CacheEntry get(Long id, Serializer<?> serializer) throws TeiidComponentException {
- Segment seg = getSegment(id);
- return seg.get(id, serializer);
+ public CacheEntry get(Long oid, Serializer<?> serializer) throws TeiidComponentException {
+ try {
+ BlockClosedLongIntHashTable map = physicalMapping.get(serializer.getId());
+ if (map == null) {
+ return null;
+ }
+ final int inode = map.get(oid);
+ if (inode == EMPTY_ADDRESS) {
+ return null;
+ }
+ final BlockManager manager = getBlockManager(serializer.getId(), oid, inode);
+ ObjectInputStream ois = new ObjectInputStream(new InputStream() {
+
+ int blockIndex;
+ BlockInfo buf;
+
+ @Override
+ public int read() throws IOException {
+ ensureBytes();
+ return buf.buf.get() & 0xff;
+ }
+
+ private void ensureBytes() {
+ if (buf == null || buf.buf.remaining() == 0) {
+ if (buf != null) {
+ buf = null;
+ }
+ buf = manager.getBlock(blockIndex++);
+ }
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len)
+ throws IOException {
+ ensureBytes();
+ len = Math.min(len, buf.buf.remaining());
+ buf.buf.get(b, off, len);
+ return len;
+ }
+ });
+ CacheEntry ce = new CacheEntry(oid);
+ ce.setSizeEstimate(ois.readInt());
+ ce.setObject(serializer.deserialize(ois));
+ ce.setPersistent(true);
+ return ce;
+ } catch(IOException e) {
+ throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", oid)); //$NON-NLS-1$
+ } catch (ClassNotFoundException e) {
+ throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", oid)); //$NON-NLS-1$
+ }
}
- private Segment getSegment(Long id) {
- return segments[id.hashCode() & (segments.length - 1)];
- }
-
@Override
public FileStore createFileStore(String name) {
return storageManager.createFileStore(name);
@@ -350,62 +653,76 @@
@Override
public void initialize() throws TeiidComponentException {
storageManager.initialize();
- int numSegments = 31 - Integer.numberOfLeadingZeros(this.segmentCount);
- segments = new Segment[1 << numSegments];
- for (int i = 0; i < segments.length; i++) {
- segments[i] = new Segment(i);
- segments[i].store = storageManager.createFileStore("segment_" + i); //$NON-NLS-1$
- }
+ int logSpace = Math.min(45, 63 - Long.numberOfLeadingZeros(this.maxBufferSpace));
+
+ blocks = 1 << Math.min(Math.max(12, logSpace -LOG_BLOCK_SIZE +1), ADDRESS_BITS); //blocks per segment
+
+ inodes = blocks>>1;
+ inodesPerBlock = BLOCK_SIZE/INODE_BYTES;
+
+ inodesInUseBlocks = computeInuseBlocks(inodes);
+ blocksInUseBlocks = computeInuseBlocks(blocks);
+
+ inodesInuse = new BlockBitSetTree(inodes - 1, new BitSetBlockManager(0));
+ blocksInuse = new BlockBitSetTree(blocks - 1, new BitSetBlockManager(inodesInUseBlocks));
+
+ store = storageManager.createFileStore("data_store"); //$NON-NLS-1$
+ systemStore = storageManager.createFileStore("system_store"); //$NON-NLS-1$
}
+
+ static int computeInuseBlocks(int number) {
+ int blockCount = (number>>LOG_BLOCK_SIZE) + ((number&BLOCK_MASK)>0?1:0);
+ return (blockCount>>3) + ((blockCount&7)>0?1:0);
+ }
@Override
public void addToCacheGroup(Long gid, Long oid) {
- Map<Long, Integer> map = physicalMapping.get(gid);
+ BlockClosedLongIntHashTable map = physicalMapping.get(gid);
if (map == null) {
return;
}
- map.put(oid, null);
+ map.put(oid, EMPTY_ADDRESS);
}
@Override
public void createCacheGroup(Long gid) {
- physicalMapping.put(gid, Collections.synchronizedMap(new HashMap<Long, Integer>()));
+ BlockClosedLongIntHashTable map = new BlockClosedLongIntHashTable(getBlockManager(gid, -1, EMPTY_ADDRESS));
+ physicalMapping.put(gid, map);
}
@Override
public void remove(Long gid, Long id) {
- Map<Long, Integer> map = physicalMapping.get(gid);
+ BlockClosedLongIntHashTable map = physicalMapping.get(gid);
if (map == null) {
return;
}
- Integer block = map.remove(id);
- if (block != null) {
- Segment s = getSegment(id);
- s.tryFree(gid, id, block);
- }
+ int inode = map.remove(id);
+ free(gid, id, inode);
}
-
+
@Override
public Collection<Long> removeCacheGroup(Long gid) {
- Map<Long, Integer> values = physicalMapping.remove(gid);
- if (values == null) {
+ BlockClosedLongIntHashTable map = physicalMapping.remove(gid);
+ if (map == null) {
return Collections.emptySet();
}
- synchronized (values) {
- for (Map.Entry<Long, Integer> entry : values.entrySet()) {
- if (entry.getValue() != null) {
- Segment s = getSegment(entry.getKey());
- s.tryFree(gid, entry.getKey(), entry.getValue());
- }
+ Map<Long, Integer> values = map.remove();
+ for (Map.Entry<Long, Integer> entry : values.entrySet()) {
+ if (entry.getValue() != null) {
+ free(gid, entry.getKey(), entry.getValue());
}
- return new HashSet<Long>(values.keySet());
}
+ return values.keySet();
}
- public void setSegmentCount(int segmentCount) {
- this.segmentCount = segmentCount;
+ void free(Long gid, Long oid, int inode) {
+ if (inode == EMPTY_ADDRESS) {
+ return;
+ }
+ BlockManager bm = getBlockManager(gid, oid, inode);
+ bm.free();
}
-
+
public void setStorageManager(StorageManager storageManager) {
this.storageManager = storageManager;
}
@@ -414,4 +731,16 @@
return storageManager;
}
+ public void setMaxBufferSpace(long maxBufferSpace) {
+ this.maxBufferSpace = maxBufferSpace;
+ }
+
+ public int getInodesInUse() {
+ return this.inodesInuse.getBitsSet();
+ }
+
+ public int getDataBlocksInUse() {
+ return this.blocksInuse.getBitsSet();
+ }
+
}
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/MemoryStorageManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/MemoryStorageManager.java 2011-09-23 04:11:11 UTC (rev 3503)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/MemoryStorageManager.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -22,6 +22,7 @@
package org.teiid.common.buffer.impl;
+import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collection;
@@ -86,6 +87,20 @@
public synchronized long getLength() {
return buffer.limit();
}
+
+ @Override
+ public synchronized ByteBuffer getBuffer(long start, int length, boolean allocate) {
+ int position = (int)start;
+ buffer.limit(position + length);
+ buffer.position(position);
+ return buffer.slice();
+ }
+
+ @Override
+ public void updateFromBuffer(ByteBuffer bb, long start)
+ throws IOException {
+ //do nothing we are sharing the bytes
+ }
}
@@ -134,7 +149,7 @@
@Override
public CacheEntry get(Long id, Serializer<?> serializer)
throws TeiidComponentException {
- Map<Long, CacheEntry> group = groups.get(id);
+ Map<Long, CacheEntry> group = groups.get(serializer.getId());
if (group != null) {
return group.get(id);
}
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java 2011-09-23 04:11:11 UTC (rev 3503)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -23,6 +23,7 @@
package org.teiid.common.buffer.impl;
import java.io.IOException;
+import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
@@ -30,6 +31,13 @@
import org.teiid.common.buffer.StorageManager;
import org.teiid.core.TeiidComponentException;
+/**
+ * A storage manager that combines smaller files into a larger
+ * logical file.
+ *
+ * The buffer methods assume that buffers cannot go beyond single
+ * file boundaries.
+ */
public class SplittableStorageManager implements StorageManager {
public static final long DEFAULT_MAX_FILESIZE = 2 * 1024l;
@@ -82,7 +90,7 @@
ensureLength(fileOffset + length);
store = storageFiles.get((int)(fileOffset/maxFileSize));
}
- long fileBegin = (int)(fileOffset%maxFileSize);
+ long fileBegin = fileOffset%maxFileSize;
length = Math.min(length, (int)Math.min(Integer.MAX_VALUE, maxFileSize - fileBegin));
store.write(fileBegin, b, offSet, length);
return length;
@@ -109,6 +117,28 @@
}
len = length;
}
+
+ @Override
+ public ByteBuffer getBuffer(long start, int length, boolean allocate) throws IOException {
+ FileStore store = null;
+ synchronized (this) {
+ ensureLength(start + length);
+ store = storageFiles.get((int)(start/maxFileSize));
+ }
+ long fileBegin = start%maxFileSize;
+ return store.getBuffer(fileBegin, length, allocate);
+ }
+
+ @Override
+ public void updateFromBuffer(ByteBuffer bb, long start)
+ throws IOException {
+ FileStore store = null;
+ synchronized (this) {
+ store = storageFiles.get((int)(start/maxFileSize));
+ }
+ long fileBegin = start%maxFileSize;
+ store.updateFromBuffer(bb, fileBegin);
+ }
@Override
public synchronized void setLength(long length) throws IOException {
Modified: trunk/engine/src/test/java/org/teiid/common/buffer/BufferManagerFactory.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/BufferManagerFactory.java 2011-09-23 04:11:11 UTC (rev 3503)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/BufferManagerFactory.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -86,7 +86,7 @@
SplittableStorageManager ssm = new SplittableStorageManager(storageManager);
ssm.setMaxFileSizeDirect(MemoryStorageManager.MAX_FILE_SIZE);
FileStoreCache fsc = new FileStoreCache();
- fsc.setSegmentCount(1);
+ fsc.setMaxBufferSpace(Runtime.getRuntime().maxMemory()/4);
fsc.setStorageManager(ssm);
fsc.initialize();
bufferManager.setCache(fsc);
Deleted: trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBitSetTree.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBitSetTree.java 2011-09-23 04:11:11 UTC (rev 3503)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBitSetTree.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -1,60 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library 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 library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
- package org.teiid.common.buffer.impl;
-
-import static org.junit.Assert.*;
-
-import java.util.BitSet;
-import java.util.Random;
-
-import org.junit.Test;
-
-public class TestBitSetTree {
-
- @Test public void testBitsSet() {
- BitSetTree bst = new BitSetTree();
- bst.set(1, true);
- bst.set(100, true);
- bst.set(10000, true);
- bst.set(1000000, true);
- assertEquals(4, bst.getBitsSet());
- }
-
- @Test public void testNextClearSet() {
- BitSetTree bst = new BitSetTree();
- BitSet bst1 = new BitSet();
- Random r = new Random(1);
- for (int i = 0; i < 1000; i++) {
- int rand = r.nextInt() & BitSetTree.MAX_INDEX;
- bst.set(rand, true);
- bst1.set(rand, true);
- }
-
- for (int i = 0; i < 10000; i++) {
- int rand = r.nextInt() & BitSetTree.MAX_INDEX;
- assertEquals(bst1.nextClearBit(rand), bst.nextClearBit(rand));
- assertEquals(bst1.nextSetBit(rand), bst.nextSetBit(rand));
- }
- }
-
-}
Copied: trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockBitSetTree.java (from rev 3502, trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBitSetTree.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockBitSetTree.java (rev 0)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockBitSetTree.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+ package org.teiid.common.buffer.impl;
+
+import static org.junit.Assert.*;
+
+import java.util.BitSet;
+import java.util.Random;
+
+import org.junit.Test;
+
+public class TestBlockBitSetTree {
+
+ @Test public void testBitsSet() {
+ BlockBitSetTree bst = new BlockBitSetTree((1 << 20) -1, new TestBlockClosedLongIntHashTable.DummyBlockManager());
+ bst.set(1, true);
+ bst.set(100, true);
+ bst.set(10000, true);
+ bst.set(1000000, true);
+ assertEquals(4, bst.getBitsSet());
+ bst.set(1, false);
+ assertEquals(3, bst.getBitsSet());
+ assertFalse(bst.get(1));
+ }
+
+ @Test public void testNextClearSet() {
+ BlockBitSetTree bst = new BlockBitSetTree((1 << 20) -1, new TestBlockClosedLongIntHashTable.DummyBlockManager());
+ BitSet bst1 = new BitSet();
+ Random r = new Random(1);
+ for (int i = 0; i < 1000; i++) {
+ int rand = r.nextInt() & bst.getMaxIndex();
+ bst.set(rand, true);
+ bst1.set(rand, true);
+ assertTrue(bst.get(rand));
+ assertEquals(bst1.nextSetBit(rand), bst.nextSetBit(rand));
+ assertEquals(String.valueOf(i), bst1.nextSetBit(rand), bst.nextSetBit(rand));
+ }
+
+ for (int i = 0; i < 10000; i++) {
+ int rand = r.nextInt() & bst.getMaxIndex();
+ assertEquals(bst1.nextClearBit(rand), bst.nextClearBit(rand));
+ assertEquals(bst1.nextSetBit(rand), bst.nextSetBit(rand));
+ }
+ }
+
+}
Property changes on: trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockBitSetTree.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockClosedLongIntHashTable.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockClosedLongIntHashTable.java (rev 0)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockClosedLongIntHashTable.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer.impl;
+
+import static org.junit.Assert.*;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Random;
+
+import org.junit.Test;
+import org.teiid.common.buffer.impl.FileStoreCache.BlockInfo;
+
+public class TestBlockClosedLongIntHashTable {
+
+ public static final class DummyBlockManager implements BlockManager {
+ List<BlockInfo> blocks = new ArrayList<BlockInfo>();
+
+ @Override
+ public int getInode() {
+ return 0;
+ }
+
+ @Override
+ public void updateBlock(BlockInfo block) {
+
+ }
+
+ @Override
+ public void free() {
+ blocks.clear();
+ }
+
+ @Override
+ public BlockInfo getBlock(int index) {
+ BlockInfo block = blocks.get(index);
+ block.buf.rewind();
+ return block;
+ }
+
+ @Override
+ public void freeBlock(int index) {
+ blocks.remove(index);
+ }
+
+ @Override
+ public BlockInfo allocateBlock(int index) {
+ assertEquals(index, blocks.size());
+ ByteBuffer result = ByteBuffer.wrap(new byte[FileStoreCache.BLOCK_SIZE]);
+ blocks.add(new BlockInfo(false, result, index, -1));
+ return blocks.get(blocks.size() - 1);
+ }
+ }
+
+ @Test public void testAgainstHashMap() {
+ BlockClosedLongIntHashTable table = new BlockClosedLongIntHashTable(new DummyBlockManager());
+ HashMap<Long, Integer> table1 = new HashMap<Long, Integer>(16);
+ for (long i = 1; i < 200000; i++) {
+ table.put(i, (int)i);
+ table1.put(i, (int)i);
+ }
+ Random r = new Random(0);
+ for (int i = 1; i < 2000000; i++) {
+ long toRemove = r.nextInt(i);
+ boolean removed = table.remove(toRemove) != BlockClosedLongIntHashTable.EMPTY;
+ assertEquals(table1.remove(toRemove) != null, removed);
+ }
+ }
+
+}
Property changes on: trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBlockClosedLongIntHashTable.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStoreCache.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStoreCache.java 2011-09-23 04:11:11 UTC (rev 3503)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStoreCache.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -27,51 +27,93 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import java.util.Arrays;
-import java.util.List;
import org.junit.Test;
import org.teiid.common.buffer.CacheEntry;
import org.teiid.common.buffer.Serializer;
+import org.teiid.core.util.UnitTestUtil;
public class TestFileStoreCache {
+ private final class SimpleSerializer implements Serializer<Integer> {
+ @Override
+ public Integer deserialize(ObjectInputStream ois)
+ throws IOException, ClassNotFoundException {
+ Integer result = ois.readInt();
+ for (int i = 0; i < result; i++) {
+ assertEquals(i, ois.readInt());
+ }
+ return result;
+ }
+
+ @Override
+ public Long getId() {
+ return 1l;
+ }
+
+ @Override
+ public void serialize(Integer obj, ObjectOutputStream oos)
+ throws IOException {
+ oos.writeInt(obj);
+ for (int i = 0; i < obj; i++) {
+ oos.writeInt(i);
+ }
+ }
+
+ @Override
+ public boolean useSoftCache() {
+ return false;
+ }
+ }
+
@Test public void testAddGetMultiBlock() throws Exception {
FileStoreCache fsc = new FileStoreCache();
- fsc.setStorageManager(new MemoryStorageManager());
+ fsc.setMaxBufferSpace(1 << 28);
+ SplittableStorageManager ssm = new SplittableStorageManager(new MemoryStorageManager());
+ ssm.setMaxFileSizeDirect(MemoryStorageManager.MAX_FILE_SIZE);
+ fsc.setStorageManager(ssm);
fsc.initialize();
+ UnitTestUtil.enableTraceLogging("org.teiid"); //$NON-NLS-1$
+
CacheEntry ce = new CacheEntry(2l);
- Serializer<Object> s = new Serializer<Object>() {
- @Override
- public Object deserialize(ObjectInputStream ois)
- throws IOException, ClassNotFoundException {
- return ois.readObject();
- }
-
- @Override
- public Long getId() {
- return 1l;
- }
-
- @Override
- public void serialize(Object obj, ObjectOutputStream oos)
- throws IOException {
- oos.writeObject(obj);
- }
-
- @Override
- public boolean useSoftCache() {
- return false;
- }
- };
+ Serializer<Integer> s = new SimpleSerializer();
fsc.createCacheGroup(s.getId());
- List<Object> cacheObject = Arrays.asList(new Object[10000]);
+ Integer cacheObject = Integer.valueOf(2);
ce.setObject(cacheObject);
fsc.add(ce, s);
ce = fsc.get(2l, s);
assertEquals(cacheObject, ce.getObject());
+
+ //test something that exceeds the direct inode data blocks
+ ce = new CacheEntry(3l);
+ cacheObject = Integer.valueOf(80000);
+ ce.setObject(cacheObject);
+ fsc.add(ce, s);
+
+ ce = fsc.get(3l, s);
+ assertEquals(cacheObject, ce.getObject());
+
+ fsc.removeCacheGroup(1l);
+
+ assertEquals(0, fsc.getDataBlocksInUse());
+ assertEquals(0, fsc.getInodesInUse());
+
+ //test something that exceeds the indirect inode data blocks
+ ce = new CacheEntry(3l);
+ fsc.createCacheGroup(s.getId());
+ cacheObject = Integer.valueOf(5000000);
+ ce.setObject(cacheObject);
+ fsc.add(ce, s);
+
+ ce = fsc.get(3l, s);
+ assertEquals(cacheObject, ce.getObject());
+
+ fsc.removeCacheGroup(1l);
+
+ assertEquals(0, fsc.getDataBlocksInUse());
+ assertEquals(0, fsc.getInodesInUse());
}
}
Modified: trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestSizeUtility.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestSizeUtility.java 2011-09-23 04:11:11 UTC (rev 3503)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestSizeUtility.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -98,18 +98,6 @@
helpTestGetSize("abcdefghij", 64); //$NON-NLS-1$
}
- public void XtestGetSizeLongString() {
- // There is no clear way of figuring out the actual size of a string that is created
- // from a StringBuffer because the buffer can sometimes be twice as big as the actual length of the string
- // Since the data comin from the connector is not created this way, this test is an inaccurate setup
- int size = 10000;
- StringBuffer str = new StringBuffer();
- for(int i=0; i<size; i++) {
- str.append("a"); //$NON-NLS-1$
- }
- helpTestGetSize(str.toString(), size+3);
- }
-
@Test public void testGetSizeRow1() {
List<Object> row = new ArrayList<Object>(1);
row.add(new Integer(0));
Modified: trunk/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java 2011-09-23 04:11:11 UTC (rev 3503)
+++ trunk/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -66,7 +66,7 @@
private long maxFileSize = SplittableStorageManager.DEFAULT_MAX_FILESIZE; // 2GB
private int maxProcessingKb = BufferManager.DEFAULT_MAX_PROCESSING_KB;
private int maxReserveKb = BufferManager.DEFAULT_RESERVE_BUFFER_KB;
- private long maxBufferSpace = FileStorageManager.DEFAULT_MAX_BUFFERSPACE;
+ private long maxBufferSpace = FileStorageManager.DEFAULT_MAX_BUFFERSPACE>>20;
private boolean inlineLobs = true;
private FileStorageManager fsm;
@@ -108,6 +108,8 @@
ssm.setMaxFileSize(maxFileSize);
FileStoreCache fsc = new FileStoreCache();
fsc.setStorageManager(ssm);
+ fsc.setMaxBufferSpace(maxBufferSpace*MB);
+ fsc.initialize();
this.bufferMgr.setCache(fsc);
} else {
this.bufferMgr.setCache(new MemoryStorageManager());
Modified: trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewReplication.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewReplication.java 2011-09-23 04:11:11 UTC (rev 3503)
+++ trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewReplication.java 2011-09-28 03:15:08 UTC (rev 3504)
@@ -30,9 +30,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
-import java.util.logging.Handler;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import org.jgroups.JChannelFactory;
import org.junit.BeforeClass;
@@ -58,16 +55,7 @@
@Test public void testReplication() throws Exception {
if (DEBUG) {
- Logger logger = Logger.getLogger("org.teiid");
- logger.setLevel(Level.FINEST);
- for (Handler h : logger.getHandlers()) {
- h.setLevel(Level.FINEST);
- }
- /*org.apache.log4j.Logger l = LogManager.getLogger("org.jgroups");
- l.setLevel(org.apache.log4j.Level.TRACE);
- ConsoleAppender ca = new ConsoleAppender(new PatternLayout());
- ca.setName("x");
- l.addAppender(ca);*/
+ UnitTestUtil.enableTraceLogging("org.teiid");
}
FakeServer server1 = createServer();
[View Less]
13 years, 6 months
teiid SVN: r3503 - in branches/as7: admin/src/main/java/org/teiid/adminapi and 17 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2011-09-23 00:11:11 -0400 (Fri, 23 Sep 2011)
New Revision: 3503
Added:
branches/as7/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataMapper.java
branches/as7/admin/src/main/resources/org/
branches/as7/admin/src/main/resources/org/teiid/
branches/as7/admin/src/main/resources/org/teiid/adminapi/
branches/as7/admin/src/main/resources/org/teiid/adminapi/i18n.properties
branches/as7/admin/src/test/resources/vdb-describe.txt
Removed:
branches/as7/…
[View More]client/src/main/resources/org/teiid/adminapi/i18n.properties
Modified:
branches/as7/admin/pom.xml
branches/as7/admin/src/main/java/org/teiid/adminapi/Admin.java
branches/as7/admin/src/main/java/org/teiid/adminapi/AdminFactory.java
branches/as7/admin/src/main/java/org/teiid/adminapi/impl/DQPManagement.java
branches/as7/admin/src/main/java/org/teiid/adminapi/impl/DataPolicyMetadata.java
branches/as7/admin/src/main/java/org/teiid/adminapi/impl/MetadataMapper.java
branches/as7/admin/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java
branches/as7/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java
branches/as7/admin/src/test/java/org/teiid/adminapi/impl/TestRequestMetadata.java
branches/as7/admin/src/test/java/org/teiid/adminapi/impl/TestSessionMetadata.java
branches/as7/admin/src/test/java/org/teiid/adminapi/impl/TestTransactionMetadata.java
branches/as7/admin/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java
branches/as7/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java
branches/as7/adminshell/src/test/java/org/teiid/adminshell/TestAdminShell.java
branches/as7/build/assembly/jboss-as7/dist.xml
branches/as7/build/kits/adminshell/connection.properties
branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/BaseOperationHandler.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/ObjectSerializer.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/OperationsConstants.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/QueryEngineOperationHandler.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/QueryEngineRemove.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidBootServicesAdd.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidExtension.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/VDBParserDeployer.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
branches/as7/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java
branches/as7/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties
branches/as7/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestAdminObjectBuilder.java
Log:
TEIID-1720: Admin operations except for the data source stuff were added
Modified: branches/as7/admin/pom.xml
===================================================================
--- branches/as7/admin/pom.xml 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/admin/pom.xml 2011-09-23 04:11:11 UTC (rev 3503)
@@ -32,12 +32,10 @@
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-controller-client</artifactId>
- <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-cli</artifactId>
- <scope>provided</scope>
</dependency>
</dependencies>
</project>
Modified: branches/as7/admin/src/main/java/org/teiid/adminapi/Admin.java
===================================================================
--- branches/as7/admin/src/main/java/org/teiid/adminapi/Admin.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/admin/src/main/java/org/teiid/adminapi/Admin.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -56,23 +56,22 @@
void changeVDBConnectionType(String vdbName, int vdbVersion, ConnectionType type) throws AdminException;
/**
- * Deploy a {@link VDB} file.
- * @param name Name of the VDB file to save under
- * @param VDB VDB.
+ * Deploy a artifact (VDB, JAR, RAR files)
+ * @param deployName Name of the VDB file to save under
+ * @param content
* @throws AdminException
*
* @return the {@link VDB} representing the current property values and runtime state.
*/
- public void deployVDB(String fileName, InputStream vdb) throws AdminException;
+ public void deploy(String deployName, InputStream content) throws AdminException;
/**
- * Delete the VDB with the given name and version
- * @param vdbName
- * @param version
+ * Undeploy artifact (VDB, JAR, RAR files)
+ * @param deployedName
* @throws AdminException
*/
- void deleteVDB(String vdbName, int vdbVersion) throws AdminException;
+ void undeploy(String deployedName) throws AdminException;
/**
* Get the VDBs that currently deployed in the system
@@ -81,7 +80,7 @@
* same name in the Collection but they will differ by VDB version.
* @throws AdminException
*/
- Set<VDB> getVDBs() throws AdminException;
+ Set<? extends VDB> getVDBs() throws AdminException;
/**
* Get the VDB
@@ -90,7 +89,7 @@
* @throws AdminException
* @return
*/
- VDB getVDB(String vdbName, int vbdVersion) throws AdminException;
+ VDB getVDB(String vdbName, int vdbVersion) throws AdminException;
/**
* Get the translators that are available in the configuration
@@ -98,7 +97,7 @@
* @return Collection of {@link Translator}
* @throws AdminException
*/
- Collection<Translator> getTranslators() throws AdminException;
+ Collection<? extends Translator> getTranslators() throws AdminException;
/**
* Get the translator by the given the deployed name.
@@ -128,21 +127,21 @@
* @return Collection of {@link Session}
* @throws AdminException
*/
- Collection<Session> getSessions() throws AdminException;
+ Collection<? extends Session> getSessions() throws AdminException;
/**
* Get the all Requests that are currently in process
* @return Collection of {@link Request}
* @throws AdminException
*/
- Collection<Request> getRequests() throws AdminException;
+ Collection<? extends Request> getRequests() throws AdminException;
/**
* Get the Requests for the given session
* @return Collection of {@link Request}
* @throws AdminException
*/
- Collection<Request> getRequestsForSession(String sessionId) throws AdminException;
+ Collection<? extends Request> getRequestsForSession(String sessionId) throws AdminException;
/**
@@ -151,7 +150,7 @@
* @return
* @throws AdminException
*/
- Collection<PropertyDefinition> getTemplatePropertyDefinitions(String templateName) throws AdminException;
+ Collection<? extends PropertyDefinition> getTemplatePropertyDefinitions(String templateName) throws AdminException;
/**
@@ -159,7 +158,7 @@
* @return
* @throws AdminException
*/
- Collection<Transaction> getTransactions() throws AdminException;
+ Collection<? extends Transaction> getTransactions() throws AdminException;
/**
* Clear the cache or caches specified by the cacheIdentifier.
Modified: branches/as7/admin/src/main/java/org/teiid/adminapi/AdminFactory.java
===================================================================
--- branches/as7/admin/src/main/java/org/teiid/adminapi/AdminFactory.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/admin/src/main/java/org/teiid/adminapi/AdminFactory.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -22,27 +22,37 @@
package org.teiid.adminapi;
+import static org.jboss.as.controller.client.helpers.ClientConstants.DEPLOYMENT_REMOVE_OPERATION;
+import static org.jboss.as.controller.client.helpers.ClientConstants.DEPLOYMENT_UNDEPLOY_OPERATION;
+
import java.io.IOException;
import java.io.InputStream;
import java.net.UnknownHostException;
-import java.util.Collection;
-import java.util.List;
-import java.util.Properties;
-import java.util.Set;
+import java.util.*;
import javax.security.auth.callback.*;
import javax.security.sasl.RealmCallback;
import javax.security.sasl.RealmChoiceCallback;
import org.jboss.as.cli.Util;
+import org.jboss.as.cli.operation.OperationFormatException;
import org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress;
+import org.jboss.as.cli.operation.impl.DefaultOperationRequestBuilder;
import org.jboss.as.controller.client.ModelControllerClient;
+import org.jboss.as.protocol.old.StreamUtils;
+import org.jboss.dmr.ModelNode;
import org.teiid.adminapi.VDB.ConnectionType;
+import org.teiid.adminapi.impl.*;
+import org.teiid.adminapi.impl.VDBMetadataMapper.RequestMetadataMapper;
+import org.teiid.adminapi.impl.VDBMetadataMapper.SessionMetadataMapper;
+import org.teiid.adminapi.impl.VDBMetadataMapper.TransactionMetadataMapper;
+import org.teiid.core.util.ObjectConverterUtil;
/**
* Singleton factory for class for creating Admin connections to the Teiid
*/
+@SuppressWarnings("nls")
public class AdminFactory {
private static AdminFactory INSTANCE = new AdminFactory();
@@ -64,7 +74,7 @@
}
if(port < 0) {
- port = 9990;
+ port = 9999;
}
try {
@@ -81,7 +91,7 @@
}
System.out.println("The controller is not available at " + host + ":" + port); //$NON-NLS-1$ //$NON-NLS-2$
} catch (UnknownHostException e) {
- System.out.println("Failed to resolve host '" + host + "': " + e.getLocalizedMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ throw new AdminProcessingException("Failed to resolve host '" + host + "': " + e.getLocalizedMessage()); //$NON-NLS-1$ //$NON-NLS-2$
}
return null;
}
@@ -128,177 +138,672 @@
}
private class AdminImpl implements Admin{
+ private ModelControllerClient connection;
+ private boolean domainMode = false;
+
public AdminImpl (ModelControllerClient connection) {
-
+ this.connection = connection;
+ List<String> nodeTypes = Util.getNodeTypes(connection, new DefaultOperationRequestAddress());
+ if (!nodeTypes.isEmpty()) {
+ domainMode = nodeTypes.contains("server-group"); //$NON-NLS-1$
+ }
}
-
+
@Override
- public void addDataRoleMapping(String vdbName, int vdbVersion,
- String dataRole, String mappedRoleName) throws AdminException {
- // rameshTODO Auto-generated method stub
-
+ public void clearCache(String cacheType) throws AdminException {
+ final ModelNode request = buildRequest("teiid", "clear-cache", "cache-type", cacheType);//$NON-NLS-1$ //$NON-NLS-2$
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (!Util.isSuccess(outcome)) {
+ throw new AdminProcessingException(Util.getFailureDescription(outcome));
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
}
@Override
- public void assignToModel(String vdbName, int vdbVersion,
- String modelName, String sourceName, String translatorName,
- String dsName) throws AdminException {
- // rameshTODO Auto-generated method stub
-
+ public void clearCache(String cacheType, String vdbName, int vdbVersion) throws AdminException {
+ final ModelNode request = buildRequest("teiid", "clear-cache",
+ "cache-type", cacheType,
+ "vdb-name", vdbName,
+ "vdb-version", String.valueOf(vdbVersion));//$NON-NLS-1$ //$NON-NLS-2$
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (!Util.isSuccess(outcome)) {
+ throw new AdminProcessingException(Util.getFailureDescription(outcome));
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
}
@Override
- public void cancelRequest(String sessionId, long executionId)
- throws AdminException {
- // rameshTODO Auto-generated method stub
-
+ public void close() {
+ if (this.connection != null) {
+ StreamUtils.safeClose(this.connection);
+ this.connection = null;
+ this.domainMode = false;
+ }
}
-
- @Override
- public void changeVDBConnectionType(String vdbName, int vdbVersion,
- ConnectionType type) throws AdminException {
- // rameshTODO Auto-generated method stub
-
+
+ private void createConnectionFactoryRequest(String deploymentName, String templateName, Properties properties) throws AdminException {
+ DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
+ try {
+ builder.operationName("add");
+ builder.addNode("subsystem", "resource-adapters"); //$NON-NLS-1$ //$NON-NLS-2$
+ builder.addNode("resource-adapter", templateName); //$NON-NLS-1$
+
+ builder.addProperty("archive", templateName);
+ builder.addProperty("transaction-support", properties.getProperty("transaction-support", "NoTransaction"));
+ properties.remove("transaction-support");
+
+
+ } catch (OperationFormatException e) {
+ throw new IllegalStateException("Failed to build operation", e); //$NON-NLS-1$
+ }
+
+
}
@Override
- public void clearCache(String cacheType) throws AdminException {
- // rameshTODO Auto-generated method stub
-
+ public void createDataSource(String deploymentName, String templateName, Properties properties) throws AdminException {
+ DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
+ final ModelNode request;
+ try {
+ // data-source jdbc-driver xa-data-source resource-adapters
+ if (templateName.equals("data-source")) {
+ builder.addNode("subsystem", "datasources"); //$NON-NLS-1$ //$NON-NLS-2$
+ builder.addNode("data-source", deploymentName); //$NON-NLS-1$
+ }
+ else if (templateName.equals("xa-data-source")) {
+ builder.addNode("subsystem", "datasources"); //$NON-NLS-1$ //$NON-NLS-2$
+ builder.addNode("xa-data-source", deploymentName); //$NON-NLS-1$
+ }
+ else if (templateName.equals("resource-adapters")) {
+ builder.addNode("subsystem", "resource-adapters"); //$NON-NLS-1$ //$NON-NLS-2$
+ builder.addNode("resource-adapter", deploymentName); //$NON-NLS-1$
+ }
+
+ builder.operationName("add");
+ request = builder.buildRequest();
+
+ builder.addProperty("jndi-name", "java:/"+deploymentName);
+ Enumeration keys = properties.propertyNames();
+ while (keys.hasMoreElements()) {
+ String key = (String)keys.nextElement();
+ builder.addProperty(key, properties.getProperty(key));
+ }
+ } catch (OperationFormatException e) {
+ throw new IllegalStateException("Failed to build operation", e); //$NON-NLS-1$
+ }
+
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (!Util.isSuccess(outcome)) {
+ throw new AdminProcessingException(Util.getFailureDescription(outcome));
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
}
@Override
- public void clearCache(String cacheType, String vdbName, int vdbVersion)
- throws AdminException {
+ public void deleteDataSource(String deployedName) throws AdminException {
// rameshTODO Auto-generated method stub
}
@Override
- public void close() {
- // rameshTODO Auto-generated method stub
-
- }
+ public void undeploy(String deployedName) throws AdminException {
+ try {
+ ModelNode request = buildUndeployRequest(deployedName);
- @Override
- public void createDataSource(String deploymentName,
- String templateName, Properties properties)
- throws AdminException {
- // rameshTODO Auto-generated method stub
-
+ ModelNode outcome = this.connection.execute(request);
+ if (!Util.isSuccess(outcome)) {
+ throw new AdminProcessingException(Util.getFailureDescription(outcome));
+ }
+ } catch (OperationFormatException e) {
+ throw new AdminProcessingException(e);
+ } catch (IOException e) {
+ throw new AdminProcessingException(e);
+ }
}
+
+ public ModelNode buildUndeployRequest(String name) throws OperationFormatException {
+ ModelNode composite = new ModelNode();
+ composite.get("operation").set("composite");
+ composite.get("address").setEmptyList();
+ ModelNode steps = composite.get("steps");
- @Override
- public void deleteDataSource(String deployedName) throws AdminException {
- // rameshTODO Auto-generated method stub
-
- }
+ DefaultOperationRequestBuilder builder;
+ if(this.domainMode) {
+ final List<String> serverGroups = Util.getServerGroups(this.connection);
+
+ for (String group : serverGroups){
+ ModelNode groupStep = Util.configureDeploymentOperation(DEPLOYMENT_UNDEPLOY_OPERATION, name, group);
+ steps.add(groupStep);
+ }
+
+ for (String group : serverGroups) {
+ ModelNode groupStep = Util.configureDeploymentOperation(DEPLOYMENT_REMOVE_OPERATION, name, group);
+ steps.add(groupStep);
+ }
+ } else if(Util.isDeployedAndEnabledInStandalone(name, this.connection)) {
+ builder = new DefaultOperationRequestBuilder();
+ builder.setOperationName("undeploy");
+ builder.addNode("deployment", name);
+ steps.add(builder.buildRequest());
+ }
+
+ // remove content
+ builder = new DefaultOperationRequestBuilder();
+ builder.setOperationName("remove");
+ builder.addNode("deployment", name);
+ steps.add(builder.buildRequest());
+
+ return composite;
+ }
+
@Override
- public void deleteVDB(String vdbName, int vdbVersion)
- throws AdminException {
- // rameshTODO Auto-generated method stub
-
+ public void deploy(String deployName, InputStream vdb) throws AdminException {
+ ModelNode request = buildDeployVDBRequest(deployName, vdb);
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (!Util.isSuccess(outcome)) {
+ throw new AdminProcessingException(Util.getFailureDescription(outcome));
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
}
- @Override
- public void deployVDB(String fileName, InputStream vdb)
- throws AdminException {
- // rameshTODO Auto-generated method stub
-
+ private ModelNode buildDeployVDBRequest(String fileName, InputStream vdb) throws AdminProcessingException {
+ try {
+ if (Util.isDeploymentInRepository(fileName, this.connection)){
+ // replace
+ DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
+ builder = new DefaultOperationRequestBuilder();
+ builder.setOperationName("full-replace-deployment");
+ builder.addProperty("name", fileName);
+ byte[] bytes = ObjectConverterUtil.convertToByteArray(vdb);
+ builder.getModelNode().get("content").get(0).get("bytes").set(bytes);
+ return builder.buildRequest();
+ }
+
+ ModelNode composite = new ModelNode();
+ composite.get("operation").set("composite");
+ composite.get("address").setEmptyList();
+ ModelNode steps = composite.get("steps");
+
+ DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
+ builder.setOperationName("add");
+ builder.addNode("deployment", fileName);
+
+ byte[] bytes = ObjectConverterUtil.convertToByteArray(vdb);
+ builder.getModelNode().get("content").get(0).get("bytes").set(bytes);
+ steps.add(builder.buildRequest());
+
+ // deploy
+ if (this.domainMode) {
+ List<String> serverGroups = Util.getServerGroups(this.connection);
+ for (String serverGroup : serverGroups) {
+ steps.add(Util.configureDeploymentOperation("add", fileName, serverGroup));
+ }
+ for (String serverGroup : serverGroups) {
+ steps.add(Util.configureDeploymentOperation("deploy", fileName, serverGroup));
+ }
+ } else {
+ builder = new DefaultOperationRequestBuilder();
+ builder.setOperationName("deploy");
+ builder.addNode("deployment", fileName);
+ steps.add(builder.buildRequest());
+ }
+ return composite;
+ } catch (OperationFormatException e) {
+ throw new AdminProcessingException(e);
+ } catch (IOException e) {
+ throw new AdminProcessingException(e);
+ }
}
@Override
- public CacheStatistics getCacheStats(String cacheType)
- throws AdminException {
- // rameshTODO Auto-generated method stub
- return null;
+ public CacheStatistics getCacheStats(String cacheType) throws AdminException {
+ final ModelNode request = buildRequest("teiid", "cache-statistics", "cache-type", cacheType);//$NON-NLS-1$ //$NON-NLS-2$
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (Util.isSuccess(outcome)) {
+ if (outcome.hasDefined("result")) {
+ ModelNode result = outcome.get("result");
+ return VDBMetadataMapper.CacheStatisticsMetadataMapper.INSTANCE.unwrap(result);
+ }
+
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
+ return null;
}
@Override
public Collection<String> getCacheTypes() throws AdminException {
- // rameshTODO Auto-generated method stub
- return null;
+ final ModelNode request = buildRequest("teiid", "cache-types");//$NON-NLS-1$ //$NON-NLS-2$
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (Util.isSuccess(outcome)) {
+ return Util.getList(outcome);
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
+ return Collections.emptyList();
}
+ private List<String> getChildNodeNames(String subsystem, String childNode) throws AdminException {
+ final ModelNode request = buildRequest(subsystem, "read-children-names", "child-type", childNode);//$NON-NLS-1$
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (Util.isSuccess(outcome)) {
+ return Util.getList(outcome);
+ }
+ } catch (IOException e) {
+ throw new AdminProcessingException(e);
+ }
+ return Collections.emptyList();
+
+ }
+
+ /**
+ * /subsystem=datasources:read-children-names(child-type=data-source)
+ * /subsystem=resource-adapters/resource-adapter={rar-file}:read-resource
+ * @see org.teiid.adminapi.Admin#getDataSourceNames()
+ */
@Override
public Collection<String> getDataSourceNames() throws AdminException {
- // rameshTODO Auto-generated method stub
- return null;
+ Set<String> datasourceNames = new HashSet<String>();
+ datasourceNames.addAll(getChildNodeNames("datasources", "data-source"));
+ datasourceNames.addAll(getChildNodeNames("datasources", "xa-data-source"));
+
+ Set<String> resourceAdapters = getResourceAdapterNames();
+ for (String resource:resourceAdapters) {
+
+ DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
+ try {
+ builder.addNode("subsystem", "resource-adapters"); //$NON-NLS-1$ //$NON-NLS-2$
+ builder.addNode("resource-adapter", resource); //$NON-NLS-1$ //$NON-NLS-2$
+ builder.operationName("read-resource");
+ ModelNode request = builder.buildRequest();
+
+ ModelNode outcome = this.connection.execute(request);
+ if (Util.isSuccess(outcome)) {
+ if (outcome.hasDefined("result")) {
+ ModelNode result = outcome.get("result");
+ if (result.hasDefined("connection-definitions")) {
+ List<ModelNode> connDefs = result.get("connection-definitions").asList();
+ for (ModelNode conn:connDefs) {
+ datasourceNames.add(conn.get("jndi-name").asString());
+ }
+ }
+ }
+ }
+ } catch (OperationFormatException e) {
+ throw new AdminProcessingException("Failed to build operation", e); //$NON-NLS-1$
+ } catch (IOException e) {
+ throw new AdminProcessingException("Failed to build operation", e); //$NON-NLS-1$
+ }
+ }
+ return datasourceNames;
}
+
+ /**
+ * This will get all deplyed RAR names
+ * /subsystem=resource-adapters:read-children-names(child-type=resource-adapter)
+ * @return
+ * @throws AdminException
+ */
+ private Set<String> getResourceAdapterNames() throws AdminException {
+ Set<String> templates = new HashSet<String>();
+ final ModelNode request = buildRequest("resource-adapters", "read-children-names", "child-type", "resource-adapter");//$NON-NLS-1$
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (Util.isSuccess(outcome)) {
+ templates.addAll(Util.getList(outcome));
+ return templates;
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
+ return Collections.emptySet();
+ }
+
@Override
public Set<String> getDataSourceTemplateNames() throws AdminException {
- // rameshTODO Auto-generated method stub
- return null;
+ Set<String> templates = new HashSet<String>();
+ templates.add("data-source");
+ templates.add("xa-data-source");
+ templates.addAll(getResourceAdapterNames());
+ return templates;
}
+
+ @Override
+ public WorkerPoolStatistics getWorkerPoolStats() throws AdminException {
+ final ModelNode request = buildEngineRequest("workerpool-statistics");//$NON-NLS-1$
+ if (request != null) {
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (Util.isSuccess(outcome)) {
+ if (outcome.hasDefined("result")) {
+ ModelNode result = outcome.get("result");
+ return VDBMetadataMapper.WorkerPoolStatisticsMetadataMapper.INSTANCE.unwrap(result);
+ }
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
+ }
+ return null;
+ }
+
@Override
- public Collection<Request> getRequests() throws AdminException {
- // rameshTODO Auto-generated method stub
- return null;
+ public void cancelRequest(String sessionId, long executionId) throws AdminException {
+ final ModelNode request = buildEngineRequest("terminate-session", "session", sessionId, "execution-id", String.valueOf(executionId));//$NON-NLS-1$
+ if (request == null) {
+ return;
+ }
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (!Util.isSuccess(outcome)) {
+ throw new AdminProcessingException(Util.getFailureDescription(outcome));
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
}
-
+
@Override
- public Collection<Request> getRequestsForSession(String sessionId)
- throws AdminException {
- // rameshTODO Auto-generated method stub
- return null;
+ public Collection<? extends Request> getRequests() throws AdminException {
+ final ModelNode request = buildEngineRequest("list-requests");//$NON-NLS-1$
+ if (request != null) {
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (Util.isSuccess(outcome)) {
+ return getList(outcome, RequestMetadataMapper.INSTANCE);
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
+ }
+ return Collections.emptyList();
}
@Override
- public Collection<Session> getSessions() throws AdminException {
- // rameshTODO Auto-generated method stub
- return null;
+ public Collection<? extends Request> getRequestsForSession(String sessionId) throws AdminException {
+ final ModelNode request = buildEngineRequest("requests-per-session", "session", sessionId);//$NON-NLS-1$
+ if (request != null) {
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (Util.isSuccess(outcome)) {
+ return getList(outcome, RequestMetadataMapper.INSTANCE);
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
+ }
+ return Collections.emptyList();
}
@Override
- public Collection<PropertyDefinition> getTemplatePropertyDefinitions(
- String templateName) throws AdminException {
- // rameshTODO Auto-generated method stub
- return null;
+ public Collection<? extends Session> getSessions() throws AdminException {
+ final ModelNode request = buildEngineRequest("list-sessions");//$NON-NLS-1$
+ if (request != null) {
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (Util.isSuccess(outcome)) {
+ return getList(outcome, SessionMetadataMapper.INSTANCE);
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
+ }
+ return Collections.emptyList();
}
@Override
- public Collection<Transaction> getTransactions() throws AdminException {
+ public Collection<PropertyDefinition> getTemplatePropertyDefinitions(String templateName) throws AdminException {
// rameshTODO Auto-generated method stub
return null;
}
@Override
- public Translator getTranslator(String deployedName)
- throws AdminException {
- // rameshTODO Auto-generated method stub
- return null;
+ public Collection<? extends Transaction> getTransactions() throws AdminException {
+ final ModelNode request = buildEngineRequest("list-transactions");//$NON-NLS-1$
+ if (request != null) {
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (Util.isSuccess(outcome)) {
+ return getList(outcome, TransactionMetadataMapper.INSTANCE);
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
+ }
+ return Collections.emptyList();
}
+
+ @Override
+ public void terminateSession(String sessionId) throws AdminException {
+ final ModelNode request = buildEngineRequest("terminate-session", "session", sessionId);//$NON-NLS-1$
+ if (request == null) {
+ return;
+ }
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (!Util.isSuccess(outcome)) {
+ throw new AdminProcessingException(Util.getFailureDescription(outcome));
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
+ }
@Override
- public Collection<Translator> getTranslators() throws AdminException {
- // rameshTODO Auto-generated method stub
+ public void terminateTransaction(String transactionId) throws AdminException {
+ final ModelNode request = buildEngineRequest("terminate-transaction", "xid", transactionId);//$NON-NLS-1$
+ if (request == null) {
+ return;
+ }
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (!Util.isSuccess(outcome)) {
+ throw new AdminProcessingException(Util.getFailureDescription(outcome));
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
+ }
+
+ @Override
+ public Translator getTranslator(String deployedName) throws AdminException {
+ final ModelNode request = buildRequest("teiid", "get-translator", "translator-name", deployedName);//$NON-NLS-1$
+ if (request == null) {
+ return null;
+ }
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (Util.isSuccess(outcome)) {
+ if (outcome.hasDefined("result")) {
+ ModelNode result = outcome.get("result");
+ return VDBMetadataMapper.VDBTranslatorMetaDataMapper.INSTANCE.unwrap(result);
+ }
+ }
+
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
return null;
}
@Override
- public VDB getVDB(String vdbName, int vbdVersion) throws AdminException {
- // rameshTODO Auto-generated method stub
- return null;
+ public Collection<? extends Translator> getTranslators() throws AdminException {
+ final ModelNode request = buildRequest("teiid", "list-translators");//$NON-NLS-1$ //$NON-NLS-2$
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (Util.isSuccess(outcome)) {
+ return getList(outcome, VDBMetadataMapper.VDBTranslatorMetaDataMapper.INSTANCE);
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
+
+ return Collections.emptyList();
}
+
+ private List<String> getEngines(ModelControllerClient client) {
+ DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
+ final ModelNode request;
+ try {
+ builder.addNode("subsystem", "teiid"); //$NON-NLS-1$ //$NON-NLS-2$
+ builder.operationName("read-children-names");
+ builder.addProperty("child-type", "query-engine");
+ request = builder.buildRequest();
+ } catch (OperationFormatException e) {
+ throw new IllegalStateException("Failed to build operation", e);
+ }
+ try {
+ ModelNode outcome = client.execute(request);
+ if (Util.isSuccess(outcome)) {
+ return Util.getList(outcome);
+ }
+ } catch (Exception e) {
+ }
+
+ return Collections.emptyList();
+ }
+
+ private ModelNode buildEngineRequest(String operationName, String... params) {
+ ModelNode composite = new ModelNode();
+ composite.get("operation").set("composite");
+ composite.get("address").setEmptyList();
+ ModelNode steps = composite.get("steps");
+
+ List<String> engines = getEngines(this.connection);
+
+ for (String engine:engines) {
+ DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
+ final ModelNode request;
+ try {
+ builder.addNode("subsystem", "teiid"); //$NON-NLS-1$ //$NON-NLS-2$
+ builder.addNode("query-engine", engine); //$NON-NLS-1$ //$NON-NLS-2$
+ builder.operationName(operationName);
+ request = builder.buildRequest();
+ if (params != null && params.length % 2 == 0) {
+ for (int i = 0; i < params.length; i+=2) {
+ builder.addProperty(params[i], params[i+1]);
+ }
+ }
+ steps.add(request);
+ } catch (OperationFormatException e) {
+ throw new IllegalStateException("Failed to build operation", e); //$NON-NLS-1$
+ }
+ }
+ return composite;
+ }
+
+ private ModelNode buildRequest(String subsystem, String operationName, String... params) {
+ DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
+ final ModelNode request;
+ try {
+ builder.addNode("subsystem", subsystem); //$NON-NLS-1$ //$NON-NLS-2$
+ builder.operationName(operationName);
+ request = builder.buildRequest();
+ if (params != null && params.length % 2 == 0) {
+ for (int i = 0; i < params.length; i+=2) {
+ builder.addProperty(params[i], params[i+1]);
+ }
+ }
+ } catch (OperationFormatException e) {
+ throw new IllegalStateException("Failed to build operation", e); //$NON-NLS-1$
+ }
+ return request;
+ }
+
+ private <T> List<T> getList(ModelNode operationResult, MetadataMapper<T> mapper) {
+ if(!operationResult.hasDefined("result")) //$NON-NLS-1$
+ return Collections.emptyList();
+
+ List<ModelNode> nodeList = operationResult.get("result").asList(); //$NON-NLS-1$
+ if(nodeList.isEmpty())
+ return Collections.emptyList();
+
+ List<T> list = new ArrayList<T>(nodeList.size());
+ for(ModelNode node : nodeList) {
+ Set<String> keys = node.keys();
+ if (!keys.isEmpty()) {
+ list.addAll(getList(node.get(0), mapper));
+ }
+ else {
+ list.add(mapper.unwrap(node));
+ }
+ }
+ return list;
+ }
+
+ public <T> Set<T> getSet(ModelNode operationResult, MetadataMapper<T> mapper) {
+ if(!operationResult.hasDefined("result")) //$NON-NLS-1$
+ return Collections.emptySet();
+
+ List<ModelNode> nodeList = operationResult.get("result").asList(); //$NON-NLS-1$
+ if(nodeList.isEmpty())
+ return Collections.emptySet();
+
+ Set<T> list = new HashSet<T>(nodeList.size());
+ for(ModelNode node : nodeList) {
+ list.add(mapper.unwrap(node));
+ }
+ return list;
+ }
+
@Override
- public Set<VDB> getVDBs() throws AdminException {
- // rameshTODO Auto-generated method stub
+ public VDB getVDB(String vdbName, int vdbVersion) throws AdminException {
+ final ModelNode request = buildRequest("teiid", "get-vdb", "vdb-name", vdbName, "vdb-version", String.valueOf(vdbVersion));//$NON-NLS-1$
+ if (request == null) {
+ return null;
+ }
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (Util.isSuccess(outcome)) {
+ if (outcome.hasDefined("result")) {
+ ModelNode result = outcome.get("result");
+ return VDBMetadataMapper.INSTANCE.unwrap(result);
+ }
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
return null;
}
@Override
- public WorkerPoolStatistics getWorkerPoolStats() throws AdminException {
- // rameshTODO Auto-generated method stub
- return null;
+ public Set<? extends VDB> getVDBs() throws AdminException {
+ final ModelNode request = buildRequest("teiid", "list-vdbs");//$NON-NLS-1$ //$NON-NLS-2$
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (Util.isSuccess(outcome)) {
+ return getSet(outcome, VDBMetadataMapper.INSTANCE);
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
+
+ return Collections.emptySet();
}
@Override
- public void markDataSourceAvailable(String jndiName)
- throws AdminException {
+ public void markDataSourceAvailable(String jndiName) throws AdminException {
// rameshTODO Auto-generated method stub
}
@@ -307,37 +812,113 @@
public void mergeVDBs(String sourceVDBName, int sourceVDBVersion,
String targetVDBName, int targetVDBVersion)
throws AdminException {
- // rameshTODO Auto-generated method stub
-
+ final ModelNode request = buildRequest("teiid", "merge-vdbs",
+ "source-vdb-name", sourceVDBName,
+ "source-vdb-name", String.valueOf(sourceVDBVersion),
+ "target-vdb-name", targetVDBName,
+ "target-vdb-version", String.valueOf(targetVDBVersion));//$NON-NLS-1$
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (!Util.isSuccess(outcome)) {
+ throw new AdminProcessingException(Util.getFailureDescription(outcome));
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
}
@Override
- public void removeDataRoleMapping(String vdbName, int vdbVersion,
- String dataRole, String mappedRoleName) throws AdminException {
- // rameshTODO Auto-generated method stub
-
- }
-
+ public void addDataRoleMapping(String vdbName, int vdbVersion, String dataRole, String mappedRoleName) throws AdminException {
+ final ModelNode request = buildRequest("teiid", "add-data-role",
+ "vdb-name", vdbName,
+ "vdb-version", String.valueOf(vdbVersion),
+ "data-role", dataRole,
+ "mapped-role", mappedRoleName);//$NON-NLS-1$ //$NON-NLS-2$
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (!Util.isSuccess(outcome)) {
+ throw new AdminProcessingException(Util.getFailureDescription(outcome));
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
+ }
+
@Override
- public void setAnyAuthenticatedForDataRole(String vdbName,
- int vdbVersion, String dataRole, boolean anyAuthenticated)
- throws AdminException {
- // rameshTODO Auto-generated method stub
-
+ public void removeDataRoleMapping(String vdbName, int vdbVersion, String dataRole, String mappedRoleName) throws AdminException {
+ final ModelNode request = buildRequest("teiid", "remove-data-role",
+ "vdb-name", vdbName,
+ "vdb-version", String.valueOf(vdbVersion),
+ "data-role", dataRole,
+ "mapped-role", mappedRoleName);//$NON-NLS-1$ //$NON-NLS-2$
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (!Util.isSuccess(outcome)) {
+ throw new AdminProcessingException(Util.getFailureDescription(outcome));
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
}
@Override
- public void terminateSession(String sessionId) throws AdminException {
- // rameshTODO Auto-generated method stub
-
+ public void setAnyAuthenticatedForDataRole(String vdbName, int vdbVersion, String dataRole, boolean anyAuthenticated) throws AdminException {
+ ModelNode request = buildRequest("teiid", "add-anyauthenticated-role",
+ "vdb-name", vdbName,
+ "vdb-version", String.valueOf(vdbVersion),
+ "data-role", dataRole); //$NON-NLS-1$ //$NON-NLS-2$
+
+ if (!anyAuthenticated) {
+ request = buildRequest("teiid", "remove-anyauthenticated-role",
+ "vdb-name", vdbName,
+ "vdb-version", String.valueOf(vdbVersion),
+ "data-role", dataRole); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (!Util.isSuccess(outcome)) {
+ throw new AdminProcessingException(Util.getFailureDescription(outcome));
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
}
@Override
- public void terminateTransaction(String transactionId)
- throws AdminException {
- // rameshTODO Auto-generated method stub
-
- }
+ public void changeVDBConnectionType(String vdbName, int vdbVersion, ConnectionType type) throws AdminException {
+ final ModelNode request = buildRequest("teiid", "change-vdb-connection-type",
+ "vdb-name", vdbName,
+ "vdb-version", String.valueOf(vdbVersion),
+ "connection-type", type.name());//$NON-NLS-1$ //$NON-NLS-2$
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (!Util.isSuccess(outcome)) {
+ throw new AdminProcessingException(Util.getFailureDescription(outcome));
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
+ }
+
+ @Override
+ public void assignToModel(String vdbName, int vdbVersion, String modelName, String sourceName, String translatorName,
+ String dsName) throws AdminException {
+ final ModelNode request = buildRequest("teiid", "assign-datasource",
+ "vdb-name", vdbName,
+ "vdb-version", String.valueOf(vdbVersion),
+ "model-name", modelName,
+ "source-name", sourceName,
+ "translator-name", translatorName,
+ "ds-name", dsName);//$NON-NLS-1$ //$NON-NLS-2$
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (!Util.isSuccess(outcome)) {
+ throw new AdminProcessingException(Util.getFailureDescription(outcome));
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(e);
+ }
+ }
}
}
Modified: branches/as7/admin/src/main/java/org/teiid/adminapi/impl/DQPManagement.java
===================================================================
--- branches/as7/admin/src/main/java/org/teiid/adminapi/impl/DQPManagement.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/admin/src/main/java/org/teiid/adminapi/impl/DQPManagement.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -33,15 +33,11 @@
WorkerPoolStatisticsMetadata getWorkerPoolStatistics();
void terminateSession(String terminateeId);
boolean cancelRequest(String sessionId, long requestId) throws AdminException;
- Collection<String> getCacheTypes();
- void clearCache(String cacheType);
- void clearCache(String cacheType, String vdbName, int version);
Collection<SessionMetadata> getActiveSessions() throws AdminException;
int getActiveSessionsCount() throws AdminException;
Collection<TransactionMetadata> getTransactions();
void terminateTransaction(String xid) throws AdminException ;
List<RequestMetadata> getLongRunningRequests();
List<RequestMetadata> getRequestsUsingVDB(String vdbName, int vdbVersion) throws AdminException;
- CacheStatisticsMetadata getCacheStatistics(String cacheType);
List<List> executeQuery(String vdbName, int version, String command, long timoutInMilli) throws AdminException;
}
Modified: branches/as7/admin/src/main/java/org/teiid/adminapi/impl/DataPolicyMetadata.java
===================================================================
--- branches/as7/admin/src/main/java/org/teiid/adminapi/impl/DataPolicyMetadata.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/admin/src/main/java/org/teiid/adminapi/impl/DataPolicyMetadata.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -110,6 +110,10 @@
this.mappedRoleNames.add(name);
}
+ public void removeMappedRoleName(String name) {
+ this.mappedRoleNames.remove(name);
+ }
+
public boolean allows(String resourceName, DataPolicy.PermissionType type) {
resourceName = resourceName.toLowerCase();
while (resourceName.length() > 0) {
Modified: branches/as7/admin/src/main/java/org/teiid/adminapi/impl/MetadataMapper.java
===================================================================
--- branches/as7/admin/src/main/java/org/teiid/adminapi/impl/MetadataMapper.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/admin/src/main/java/org/teiid/adminapi/impl/MetadataMapper.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -21,1051 +21,10 @@
*/
package org.teiid.adminapi.impl;
-import java.util.List;
-import java.util.Map;
-
import org.jboss.dmr.ModelNode;
-import org.jboss.dmr.ModelType;
-import org.teiid.adminapi.AdminPlugin;
-import org.teiid.adminapi.DataPolicy;
-import org.teiid.adminapi.Model;
-import org.teiid.adminapi.Translator;
-import org.teiid.adminapi.Request.ProcessingState;
-import org.teiid.adminapi.Request.ThreadState;
-import org.teiid.adminapi.VDB.ConnectionType;
-import org.teiid.adminapi.VDB.Status;
-import org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData;
-import org.teiid.adminapi.impl.ModelMetaData.ValidationError;
-
-public class MetadataMapper {
- private static final String VDBNAME = "vdb-name"; //$NON-NLS-1$
- private static final String CONNECTIONTYPE = "connection-type"; //$NON-NLS-1$
- private static final String STATUS = "status"; //$NON-NLS-1$
- private static final String VERSION = "vdb-version"; //$NON-NLS-1$
- private static final String URL = "url"; //$NON-NLS-1$
- private static final String MODELS = "models"; //$NON-NLS-1$
- private static final String OVERRIDE_TRANSLATORS = "override-translators"; //$NON-NLS-1$
- private static final String DESCRIPTION = "description"; //$NON-NLS-1$
- private static final String PROPERTIES = "properties"; //$NON-NLS-1$
- private static final String DYNAMIC = "dynamic"; //$NON-NLS-1$
- private static final String DATA_POLICIES = "data-policies"; //$NON-NLS-1$
-
-
- public static ModelNode wrap(VDBMetaData vdb, ModelNode node) {
- if (vdb == null) {
- return null;
- }
- node.get(ModelNodeConstants.TYPE).set(ModelType.OBJECT);
-
- node.get(VDBNAME).set(vdb.getName());
- node.get(CONNECTIONTYPE).set(vdb.getConnectionType().toString());
- node.get(STATUS).set(vdb.getStatus().toString());
- node.get(VERSION).set(vdb.getVersion());
- if (vdb.getUrl() != null) {
- }
- if (vdb.getDescription() != null) {
- node.get(DESCRIPTION).set(vdb.getDescription());
- }
- node.get(DYNAMIC).set(vdb.isDynamic());
-
- //PROPERTIES
- List<PropertyMetadata> properties = vdb.getJAXBProperties();
- if (properties!= null && !properties.isEmpty()) {
- ModelNode propsNode = node.get(CHILDREN, PROPERTIES);
- for (PropertyMetadata prop:properties) {
- propsNode.add(PropertyMetaDataMapper.wrap(prop, new ModelNode()));
- }
- }
-
- // MODELS
- Map<String, ModelMetaData> models = vdb.getModelMetaDatas();
- if (models != null && !models.isEmpty()) {
- ModelNode modelNodes = node.get(CHILDREN, MODELS);
- for(ModelMetaData model:models.values()) {
- modelNodes.add(ModelMetadataMapper.wrap(model, new ModelNode()));
- }
- }
-
- // OVERRIDE_TRANSLATORS
- List<Translator> translators = vdb.getOverrideTranslators();
- if (translators != null && !translators.isEmpty()) {
- ModelNode translatorNodes = node.get(CHILDREN, OVERRIDE_TRANSLATORS);
- for (Translator translator:translators) {
- translatorNodes.add(VDBTranslatorMetaDataMapper.wrap((VDBTranslatorMetaData)translator, new ModelNode()));
- }
- }
-
- // DATA_POLICIES
- List<DataPolicy> policies = vdb.getDataPolicies();
- if (policies != null && !policies.isEmpty()) {
- ModelNode dataPoliciesNodes = node.get(CHILDREN, DATA_POLICIES);
- for (DataPolicy policy:policies) {
- dataPoliciesNodes.add(DataPolicyMetadataMapper.wrap((DataPolicyMetadata)policy, new ModelNode()));
- }
- }
- return node;
- }
-
- public static VDBMetaData unwrap(ModelNode node) {
- if (node == null)
- return null;
-
- VDBMetaData vdb = new VDBMetaData();
- if (node.has(VDBNAME)) {
- vdb.setName(node.get(VDBNAME).asString());
- }
- if (node.has(CONNECTIONTYPE)) {
- vdb.setConnectionType(node.get(CONNECTIONTYPE).asString());
- }
- if (node.has(STATUS)) {
- vdb.setStatus(node.get(STATUS).asString());
- }
- if (node.has(VERSION)) {
- vdb.setVersion(node.get(VERSION).asInt());
- }
- if (node.has(URL)) {
- vdb.setUrl(node.get(URL).asString());
- }
- if(node.has(DESCRIPTION)) {
- vdb.setDescription(node.get(DESCRIPTION).asString());
- }
- if (node.has(DYNAMIC)) {
- vdb.setDynamic(node.get(DYNAMIC).asBoolean());
- }
-
- //PROPERTIES
- if (node.get(CHILDREN, PROPERTIES).isDefined()) {
- List<ModelNode> propNodes = node.get(CHILDREN, PROPERTIES).asList();
- for (ModelNode propNode:propNodes) {
- PropertyMetadata prop = PropertyMetaDataMapper.unwrap(propNode);
- if (prop != null) {
- vdb.addProperty(prop.getName(), prop.getValue());
- }
- }
- }
-
- // MODELS
- if (node.get(CHILDREN, MODELS).isDefined()) {
- List<ModelNode> modelNodes = node.get(CHILDREN, MODELS).asList();
- for(ModelNode modelNode:modelNodes) {
- ModelMetaData model = ModelMetadataMapper.unwrap(modelNode);
- if (model != null) {
- vdb.addModel(model);
- }
- }
- }
-
- // OVERRIDE_TRANSLATORS
- if (node.get(CHILDREN, OVERRIDE_TRANSLATORS).isDefined()) {
- List<ModelNode> translatorNodes = node.get(CHILDREN, OVERRIDE_TRANSLATORS).asList();
- for (ModelNode translatorNode:translatorNodes) {
- VDBTranslatorMetaData translator = VDBTranslatorMetaDataMapper.unwrap(translatorNode);
- if (translator != null) {
- vdb.addOverideTranslator(translator);
- }
- }
- }
-
- // DATA_POLICIES
- if (node.get(CHILDREN, DATA_POLICIES).isDefined()) {
- List<ModelNode> policiesNodes = node.get(CHILDREN, DATA_POLICIES).asList();
- for (ModelNode policyNode:policiesNodes) {
- DataPolicyMetadata policy = DataPolicyMetadataMapper.unwrap(policyNode);
- if (policy != null) {
- vdb.addDataPolicy(policy);
- }
-
- }
- }
- return vdb;
- }
-
- public static ModelNode describe(ModelNode node) {
- node.get(TYPE).set(ModelType.OBJECT);
- addAttribute(node, VDBNAME, ModelType.STRING, true);
-
- ModelNode connectionsAllowed = new ModelNode();
- connectionsAllowed.add(ConnectionType.NONE.toString());
- connectionsAllowed.add(ConnectionType.ANY.toString());
- connectionsAllowed.add(ConnectionType.BY_VERSION.toString());
- addAttribute(node, CONNECTIONTYPE, ModelType.STRING, false).get(ALLOWED).set(connectionsAllowed);
-
- ModelNode statusAllowed = new ModelNode();
- statusAllowed.add(Status.ACTIVE.toString());
- statusAllowed.add(Status.INACTIVE.toString());
- addAttribute(node, STATUS, ModelType.STRING, true).get(ALLOWED).set(statusAllowed);
-
- addAttribute(node, VERSION, ModelType.INT, true);
- addAttribute(node, URL, ModelType.STRING, false);
- addAttribute(node, DESCRIPTION, ModelType.STRING, false);
- addAttribute(node, DYNAMIC, ModelType.BOOLEAN, false);
-
- ModelNode props = node.get(CHILDREN, PROPERTIES);
- props.get(DESCRIPTION).set(AdminPlugin.Util.getString(PROPERTIES+DOT_DESC));
- PropertyMetaDataMapper.describe(props);
-
- ModelNode models = node.get(CHILDREN, MODELS);
- ModelMetadataMapper.describe(models);
- models.get(DESCRIPTION).set(AdminPlugin.Util.getString(MODELS+DOT_DESC));
- models.get(MIN_OCCURS).set(1);
-
- ModelNode translators = node.get(CHILDREN, OVERRIDE_TRANSLATORS);
- translators.get(DESCRIPTION).set(AdminPlugin.Util.getString(OVERRIDE_TRANSLATORS+DOT_DESC));
- VDBTranslatorMetaDataMapper.describe(translators);
-
- ModelNode dataPolicies = node.get(CHILDREN, DATA_POLICIES);
- dataPolicies.get(DESCRIPTION).set(AdminPlugin.Util.getString(DATA_POLICIES+DOT_DESC));
- DataPolicyMetadataMapper.describe(dataPolicies);
- return node;
- }
-
- /**
- * model metadata mapper
- */
- public static class ModelMetadataMapper {
- private static final String MODEL_NAME = "model-name"; //$NON-NLS-1$
- private static final String DESCRIPTION = "description"; //$NON-NLS-1$
- private static final String VISIBLE = "visible"; //$NON-NLS-1$
- private static final String MODEL_TYPE = "model-type"; //$NON-NLS-1$
- private static final String MODELPATH = "model-path"; //$NON-NLS-1$
- private static final String PROPERTIES = "properties"; //$NON-NLS-1$
- private static final String SOURCE_MAPPINGS = "source-mappings"; //$NON-NLS-1$
- private static final String VALIDITY_ERRORS = "validity-errors"; //$NON-NLS-1$
-
- public static ModelNode wrap(ModelMetaData model, ModelNode node) {
- if (model == null) {
- return null;
- }
- node.get(TYPE).set(ModelType.OBJECT);
-
- node.get(MODEL_NAME).set(model.getName());
- if (model.getDescription() != null) {
- node.get(DESCRIPTION).set(model.getDescription());
- }
- node.get(VISIBLE).set(model.isVisible());
- node.get(MODEL_TYPE).set(model.getModelType().toString());
- if (model.getPath() != null) {
- node.get(MODELPATH).set(model.getPath());
- }
-
- List<PropertyMetadata> properties = model.getJAXBProperties();
- if (properties!= null && !properties.isEmpty()) {
- ModelNode propsNode = node.get(CHILDREN, PROPERTIES);
- for (PropertyMetadata prop:properties) {
- propsNode.add(PropertyMetaDataMapper.wrap(prop, new ModelNode()));
- }
- }
-
- List<SourceMappingMetadata> sources = model.getSourceMappings();
- if (sources != null && !sources.isEmpty()) {
- ModelNode sourceMappingNode = node.get(CHILDREN, SOURCE_MAPPINGS);
- for(SourceMappingMetadata source:sources) {
- sourceMappingNode.add(SourceMappingMetadataMapper.wrap(source, new ModelNode()));
- }
- }
-
- List<ValidationError> errors = model.getErrors();
- if (errors != null && !errors.isEmpty()) {
- ModelNode errorsNode = node.get(CHILDREN, VALIDITY_ERRORS);
- for (ValidationError error:errors) {
- errorsNode.add(ValidationErrorMapper.wrap(error));
- }
- }
- return node;
- }
-
- public static ModelMetaData unwrap(ModelNode node) {
- if (node == null) {
- return null;
- }
-
- ModelMetaData model = new ModelMetaData();
- if (node.has(MODEL_NAME)) {
- model.setName(node.get(MODEL_NAME).asString());
- }
- if (node.has(DESCRIPTION)) {
- model.setDescription(node.get(DESCRIPTION).asString());
- }
- if (node.has(VISIBLE)) {
- model.setVisible(node.get(VISIBLE).asBoolean());
- }
- if(node.has(MODEL_TYPE)) {
- model.setModelType(node.get(MODEL_TYPE).asString());
- }
- if(node.has(MODELPATH)) {
- model.setPath(node.get(MODELPATH).asString());
- }
-
- if (node.get(CHILDREN, PROPERTIES).isDefined()) {
- List<ModelNode> propNodes = node.get(CHILDREN, PROPERTIES).asList();
- for (ModelNode propNode:propNodes) {
- PropertyMetadata prop = PropertyMetaDataMapper.unwrap(propNode);
- if (prop != null) {
- model.addProperty(prop.getName(), prop.getValue());
- }
- }
- }
-
- if (node.get(CHILDREN, SOURCE_MAPPINGS).isDefined()) {
- List<ModelNode> sourceMappingNodes = node.get(CHILDREN, SOURCE_MAPPINGS).asList();
- for (ModelNode sourceMapping:sourceMappingNodes) {
- SourceMappingMetadata source = SourceMappingMetadataMapper.unwrap(sourceMapping);
- if (source != null) {
- model.addSourceMapping(source);
- }
- }
- }
-
- if (node.get(CHILDREN, VALIDITY_ERRORS).isDefined()) {
- List<ModelNode> errorNodes = node.get(CHILDREN, VALIDITY_ERRORS).asList();
- for(ModelNode errorNode:errorNodes) {
- ValidationError error = ValidationErrorMapper.unwrap(errorNode);
- if (error != null) {
- model.addError(error);
- }
- }
- }
- return model;
- }
-
- public static ModelNode describe(ModelNode node) {
- node.get(TYPE).set(ModelType.OBJECT);
-
- ModelNode modelTypes = new ModelNode();
- modelTypes.add(Model.Type.PHYSICAL.toString());
- modelTypes.add(Model.Type.VIRTUAL.toString());
- modelTypes.add(Model.Type.FUNCTION.toString());
- modelTypes.add(Model.Type.OTHER.toString());
- addAttribute(node, MODEL_NAME, ModelType.STRING, true).get(ALLOWED).set(modelTypes);
-
- addAttribute(node, DESCRIPTION, ModelType.STRING, false);
- addAttribute(node, VISIBLE, ModelType.BOOLEAN, false);
- addAttribute(node, MODEL_TYPE, ModelType.STRING, true);
- addAttribute(node, MODELPATH, ModelType.STRING, false);
-
- ModelNode props = node.get(CHILDREN, PROPERTIES);
- props.get(DESCRIPTION).set(AdminPlugin.Util.getString(PROPERTIES+DOT_DESC));
- PropertyMetaDataMapper.describe(props);
-
- ModelNode source = node.get(CHILDREN, SOURCE_MAPPINGS);
- source.get(DESCRIPTION).set(AdminPlugin.Util.getString(SOURCE_MAPPINGS+DOT_DESC));
- SourceMappingMetadataMapper.describe(source);
-
- ModelNode errors = node.get(CHILDREN, VALIDITY_ERRORS);
- errors.get(DESCRIPTION).set(AdminPlugin.Util.getString(VALIDITY_ERRORS+DOT_DESC));
- ValidationErrorMapper.describe(errors);
-
- return node;
- }
- }
-
- /**
- * validation error mapper
- */
- public static class ValidationErrorMapper {
- private static final String ERROR_PATH = "error-path"; //$NON-NLS-1$
- private static final String SEVERITY = "severity"; //$NON-NLS-1$
- private static final String MESSAGE = "message"; //$NON-NLS-1$
-
- public static ModelNode wrap(ValidationError error) {
- if (error == null) {
- return null;
- }
-
- ModelNode node = new ModelNode();
- node.get(TYPE).set(ModelType.OBJECT);
- if (error.getPath() != null) {
- node.get(ERROR_PATH).set(error.getPath());
- }
- node.get(SEVERITY).set(error.getSeverity());
- node.get(MESSAGE).set(error.getValue());
-
- return node;
- }
-
- public static ValidationError unwrap(ModelNode node) {
- if (node == null) {
- return null;
- }
-
- ValidationError error = new ValidationError();
- if (node.has(ERROR_PATH)) {
- error.setPath(node.get(ERROR_PATH).asString());
- }
- if (node.has(SEVERITY)) {
- error.setSeverity(node.get(SEVERITY).asString());
- }
- if(node.has(MESSAGE)) {
- error.setValue(node.get(MESSAGE).asString());
- }
- return error;
- }
-
- public static ModelNode describe(ModelNode node) {
- node.get(TYPE).set(ModelType.OBJECT);
- addAttribute(node, ERROR_PATH, ModelType.STRING, false);
- addAttribute(node, SEVERITY, ModelType.STRING, true);
- addAttribute(node, MESSAGE, ModelType.STRING, true);
- return node;
- }
- }
-
- /**
- * Source Mapping Metadata mapper
- */
- public static class SourceMappingMetadataMapper {
- private static final String SOURCE_NAME = "source-name"; //$NON-NLS-1$
- private static final String JNDI_NAME = "jndi-name"; //$NON-NLS-1$
- private static final String TRANSLATOR_NAME = "translator-name"; //$NON-NLS-1$
-
- public static ModelNode wrap(SourceMappingMetadata source, ModelNode node) {
- if (source == null) {
- return null;
- }
-
- node.get(TYPE).set(ModelType.OBJECT);
-
- node.get(SOURCE_NAME).set(source.getName());
- node.get(JNDI_NAME).set(source.getConnectionJndiName());
- node.get(TRANSLATOR_NAME).set(source.getTranslatorName());
- return node;
- }
-
- public static SourceMappingMetadata unwrap(ModelNode node) {
- if (node == null) {
- return null;
- }
- SourceMappingMetadata source = new SourceMappingMetadata();
- if (node.has(SOURCE_NAME)) {
- source.setName(node.get(SOURCE_NAME).asString());
- }
- if (node.has(JNDI_NAME)) {
- source.setConnectionJndiName(node.get(JNDI_NAME).asString());
- }
- if (node.has(TRANSLATOR_NAME)) {
- source.setTranslatorName(node.get(TRANSLATOR_NAME).asString());
- }
- return source;
- }
-
- public static ModelNode describe(ModelNode node) {
- node.get(TYPE).set(ModelType.OBJECT);
- addAttribute(node, SOURCE_NAME, ModelType.STRING, true);
- addAttribute(node, JNDI_NAME, ModelType.STRING, true);
- addAttribute(node, TRANSLATOR_NAME, ModelType.STRING, true);
- return node;
- }
- }
-
- /**
- * Source Mapping Metadata mapper
- */
- public static class VDBTranslatorMetaDataMapper {
- private static final String TRANSLATOR_NAME = "translator-name"; //$NON-NLS-1$
- private static final String BASETYPE = "base-type"; //$NON-NLS-1$
- private static final String DESCRIPTION = "description"; //$NON-NLS-1$
- private static final String PROPERTIES = "properties"; //$NON-NLS-1$
- private static final String MODULE_NAME = "module-name"; //$NON-NLS-1$
-
- public static ModelNode wrap(VDBTranslatorMetaData translator, ModelNode node) {
- if (translator == null) {
- return null;
- }
- node.get(TYPE).set(ModelType.OBJECT);
-
- node.get(TRANSLATOR_NAME).set(translator.getName());
- if (translator.getType() != null) {
- node.get(BASETYPE).set(translator.getType());
- }
- if (translator.getDescription() != null) {
- node.get(DESCRIPTION).set(translator.getDescription());
- }
-
- if (translator.getModuleName() != null) {
- node.get(MODULE_NAME).set(translator.getModuleName());
- }
-
- List<PropertyMetadata> properties = translator.getJAXBProperties();
- if (properties!= null && !properties.isEmpty()) {
- ModelNode propsNode = node.get(CHILDREN, PROPERTIES);
- for (PropertyMetadata prop:properties) {
- propsNode.add(PropertyMetaDataMapper.wrap(prop, new ModelNode()));
- }
- }
- return node;
- }
-
- public static VDBTranslatorMetaData unwrap(ModelNode node) {
- if (node == null) {
- return null;
- }
- VDBTranslatorMetaData translator = new VDBTranslatorMetaData();
- if (node.has(TRANSLATOR_NAME)) {
- translator.setName(node.get(TRANSLATOR_NAME).asString());
- }
- if (node.has(BASETYPE)) {
- translator.setType(node.get(BASETYPE).asString());
- }
- if (node.has(DESCRIPTION)) {
- translator.setDescription(node.get(DESCRIPTION).asString());
- }
- if (node.has(MODULE_NAME)) {
- translator.setModuleName(node.get(MODULE_NAME).asString());
- }
-
- if (node.get(CHILDREN,PROPERTIES).isDefined()) {
- List<ModelNode> propNodes = node.get(CHILDREN, PROPERTIES).asList();
- for (ModelNode propNode:propNodes) {
- PropertyMetadata prop = PropertyMetaDataMapper.unwrap(propNode);
- if (prop != null) {
- translator.addProperty(prop.getName(), prop.getValue());
- }
- }
- }
- return translator;
- }
-
- public static ModelNode describe(ModelNode node) {
- node.get(TYPE).set(ModelType.OBJECT);
- addAttribute(node, TRANSLATOR_NAME, ModelType.STRING, true);
- addAttribute(node, BASETYPE, ModelType.STRING, true);
- addAttribute(node, DESCRIPTION, ModelType.STRING, false);
- addAttribute(node, MODULE_NAME, ModelType.STRING, false);
-
- ModelNode props = node.get(CHILDREN, PROPERTIES);
- props.get(DESCRIPTION).set(AdminPlugin.Util.getString(PROPERTIES+DOT_DESC));
- PropertyMetaDataMapper.describe(props);
- return node;
- }
- }
-
- /**
- * Property Metadata mapper
- */
- public static class PropertyMetaDataMapper {
- private static final String PROPERTY_NAME = "property-name"; //$NON-NLS-1$
- private static final String PROPERTY_VALUE = "property-value"; //$NON-NLS-1$
-
- public static ModelNode wrap(PropertyMetadata property, ModelNode node) {
- if (property == null) {
- return null;
- }
- node.get(ModelNodeConstants.TYPE).set(ModelType.OBJECT);
-
- node.get(PROPERTY_NAME).set(property.getName());
- node.get(PROPERTY_VALUE).set(property.getValue());
-
- return node;
- }
-
- public static PropertyMetadata unwrap(ModelNode node) {
- if(node == null) {
- return null;
- }
- PropertyMetadata property = new PropertyMetadata();
- if (node.has(PROPERTY_NAME)) {
- property.setName(node.get(PROPERTY_NAME).asString());
- }
- if(node.has(PROPERTY_VALUE)) {
- property.setValue(node.get(PROPERTY_VALUE).asString());
- }
- return property;
- }
-
- public static ModelNode describe(ModelNode node) {
- node.get(TYPE).set(ModelType.OBJECT);
- addAttribute(node, PROPERTY_NAME, ModelType.STRING, true);
- addAttribute(node, PROPERTY_VALUE, ModelType.STRING, true);
- return node;
- }
- }
-
- /**
- * DataPolicy Metadata mapper
- */
- public static class DataPolicyMetadataMapper {
- private static final String POLICY_NAME = "policy-name"; //$NON-NLS-1$
- private static final String DATA_PERMISSIONS = "data-permissions"; //$NON-NLS-1$
- private static final String MAPPED_ROLE_NAMES = "mapped-role-names"; //$NON-NLS-1$
- private static final String ALLOW_CREATE_TEMP_TABLES = "allow-create-temp-tables"; //$NON-NLS-1$
- private static final String ANY_AUTHENTICATED = "any-authenticated"; //$NON-NLS-1$
-
- public static ModelNode wrap(DataPolicyMetadata policy, ModelNode node) {
- if (policy == null) {
- return null;
- }
- node.get(ModelNodeConstants.TYPE).set(ModelType.OBJECT);
-
- node.get(POLICY_NAME).set(policy.getName());
- if (policy.getDescription() != null) {
- node.get(DESCRIPTION).set(policy.getDescription());
- }
- if (policy.isAllowCreateTemporaryTables() != null) {
- node.get(ALLOW_CREATE_TEMP_TABLES).set(policy.isAllowCreateTemporaryTables());
- }
- node.get(ANY_AUTHENTICATED).set(policy.isAnyAuthenticated());
-
- //DATA_PERMISSIONS
- List<DataPolicy.DataPermission> permissions = policy.getPermissions();
- if (permissions != null && !permissions.isEmpty()) {
- ModelNode permissionNodes = node.get(CHILDREN, DATA_PERMISSIONS);
- for (DataPolicy.DataPermission dataPermission:permissions) {
- permissionNodes.add(PermissionMetaDataMapper.wrap((PermissionMetaData)dataPermission, new ModelNode()));
- }
- }
-
- //MAPPED_ROLE_NAMES
- if (policy.getMappedRoleNames() != null && !policy.getMappedRoleNames().isEmpty()) {
- ModelNode mappedRoleNodes = node.get(CHILDREN, MAPPED_ROLE_NAMES);
- for (String role:policy.getMappedRoleNames()) {
- mappedRoleNodes.add(role);
- }
- }
- return node;
- }
-
- public static DataPolicyMetadata unwrap(ModelNode node) {
- if(node == null) {
- return null;
- }
- DataPolicyMetadata policy = new DataPolicyMetadata();
- if (node.has(POLICY_NAME)) {
- policy.setName(node.get(POLICY_NAME).asString());
- }
- if (node.has(DESCRIPTION)) {
- policy.setDescription(node.get(DESCRIPTION).asString());
- }
- if (node.has(ALLOW_CREATE_TEMP_TABLES)) {
- policy.setAllowCreateTemporaryTables(node.get(ALLOW_CREATE_TEMP_TABLES).asBoolean());
- }
- if (node.has(ANY_AUTHENTICATED)) {
- policy.setAnyAuthenticated(node.get(ANY_AUTHENTICATED).asBoolean());
- }
-
- //DATA_PERMISSIONS
- if (node.get(CHILDREN, DATA_PERMISSIONS).isDefined()) {
- List<ModelNode> permissionNodes = node.get(CHILDREN, DATA_PERMISSIONS).asList();
- for (ModelNode permissionNode:permissionNodes) {
- PermissionMetaData permission = PermissionMetaDataMapper.unwrap(permissionNode);
- if (permission != null) {
- policy.addPermission(permission);
- }
- }
- }
-
- //MAPPED_ROLE_NAMES
- if (node.get(CHILDREN, MAPPED_ROLE_NAMES).isDefined()) {
- List<ModelNode> roleNameNodes = node.get(CHILDREN, MAPPED_ROLE_NAMES).asList();
- for (ModelNode roleNameNode:roleNameNodes) {
- policy.addMappedRoleName(roleNameNode.asString());
- }
- }
- return policy;
- }
-
- public static ModelNode describe(ModelNode node) {
- node.get(TYPE).set(ModelType.OBJECT);
- addAttribute(node, POLICY_NAME, ModelType.STRING, true);
- addAttribute(node, DESCRIPTION, ModelType.STRING, false);
- addAttribute(node, ALLOW_CREATE_TEMP_TABLES, ModelType.BOOLEAN, false);
- addAttribute(node, ANY_AUTHENTICATED, ModelType.BOOLEAN, false);
-
- ModelNode permissions = node.get(CHILDREN, DATA_PERMISSIONS);
- PropertyMetaDataMapper.describe(permissions);
- permissions.get(DESCRIPTION).set(AdminPlugin.Util.getString(DATA_PERMISSIONS+DOT_DESC));
- permissions.get(MIN_OCCURS).set(1);
-
- ModelNode roleNames = node.get(CHILDREN, MAPPED_ROLE_NAMES);
- roleNames.get(TYPE).set(ModelType.LIST);
- roleNames.get(DESCRIPTION).set(AdminPlugin.Util.getString(MAPPED_ROLE_NAMES+DOT_DESC));
- roleNames.get("value-type").set(ModelType.STRING); //$NON-NLS-1$
- return node;
- }
- }
-
- public static class PermissionMetaDataMapper{
- private static final String RESOURCE_NAME = "resource-name"; //$NON-NLS-1$
- private static final String ALLOW_CREATE = "allow-create"; //$NON-NLS-1$
- private static final String ALLOW_DELETE = "allow-delete"; //$NON-NLS-1$
- private static final String ALLOW_UPADTE = "allow-update"; //$NON-NLS-1$
- private static final String ALLOW_READ = "allow-read"; //$NON-NLS-1$
- private static final String ALLOW_EXECUTE = "allow-execute"; //$NON-NLS-1$
- private static final String ALLOW_ALTER = "allow-alter"; //$NON-NLS-1$
-
-
-
- public static ModelNode wrap(PermissionMetaData permission, ModelNode node) {
- if (permission == null) {
- return null;
- }
-
- node.get(ModelNodeConstants.TYPE).set(ModelType.OBJECT);
-
- node.get(RESOURCE_NAME).set(permission.getResourceName());
- if (permission.getAllowCreate() != null) {
- node.get(ALLOW_CREATE).set(permission.getAllowCreate().booleanValue());
- }
- if (permission.getAllowDelete() != null) {
- node.get(ALLOW_DELETE).set(permission.getAllowDelete().booleanValue());
- }
- if (permission.getAllowUpdate() != null) {
- node.get(ALLOW_UPADTE).set(permission.getAllowUpdate().booleanValue());
- }
- if (permission.getAllowRead() != null) {
- node.get(ALLOW_READ).set(permission.getAllowRead().booleanValue());
- }
- if (permission.getAllowExecute() != null) {
- node.get(ALLOW_EXECUTE).set(permission.getAllowExecute().booleanValue());
- }
- if(permission.getAllowAlter() != null) {
- node.get(ALLOW_ALTER).set(permission.getAllowAlter().booleanValue());
- }
- return node;
- }
-
- public static PermissionMetaData unwrap(ModelNode node) {
- if (node == null) {
- return null;
- }
-
- PermissionMetaData permission = new PermissionMetaData();
- if (node.get(RESOURCE_NAME) != null) {
- permission.setResourceName(node.get(RESOURCE_NAME).asString());
- }
- if (node.has(ALLOW_CREATE)) {
- permission.setAllowCreate(node.get(ALLOW_CREATE).asBoolean());
- }
- if (node.has(ALLOW_DELETE)) {
- permission.setAllowDelete(node.get(ALLOW_DELETE).asBoolean());
- }
- if (node.has(ALLOW_UPADTE)) {
- permission.setAllowUpdate(node.get(ALLOW_UPADTE).asBoolean());
- }
- if (node.has(ALLOW_READ)) {
- permission.setAllowRead(node.get(ALLOW_READ).asBoolean());
- }
- if (node.has(ALLOW_EXECUTE)) {
- permission.setAllowExecute(node.get(ALLOW_EXECUTE).asBoolean());
- }
- if (node.has(ALLOW_ALTER)) {
- permission.setAllowAlter(node.get(ALLOW_ALTER).asBoolean());
- }
- return permission;
- }
- public static ModelNode describe(ModelNode node) {
- addAttribute(node, RESOURCE_NAME, ModelType.STRING, true);
- addAttribute(node, ALLOW_CREATE, ModelType.BOOLEAN, false);
- addAttribute(node, ALLOW_DELETE, ModelType.BOOLEAN, false);
- addAttribute(node, ALLOW_UPADTE, ModelType.BOOLEAN, false);
- addAttribute(node, ALLOW_READ, ModelType.BOOLEAN, false);
- addAttribute(node, ALLOW_EXECUTE, ModelType.BOOLEAN, false);
- addAttribute(node, ALLOW_ALTER, ModelType.BOOLEAN, false);
- return node;
- }
- }
-
- public static class CacheStatisticsMetadataMapper {
- private static final String HITRATIO = "hit-ratio"; //$NON-NLS-1$
- private static final String TOTAL_ENTRIES = "total-entries"; //$NON-NLS-1$
- private static final String REQUEST_COUNT = "request-count"; //$NON-NLS-1$
-
- public static ModelNode wrap(CacheStatisticsMetadata object, ModelNode node) {
- if (object == null)
- return null;
-
- node.get(ModelNodeConstants.TYPE).set(ModelType.OBJECT);
-
- node.get(TOTAL_ENTRIES).set(object.getTotalEntries());
- node.get(HITRATIO).set(object.getHitRatio());
- node.get(REQUEST_COUNT).set(object.getRequestCount());
-
- return node;
- }
-
- public static CacheStatisticsMetadata unwrap(ModelNode node) {
- if (node == null)
- return null;
-
- CacheStatisticsMetadata cache = new CacheStatisticsMetadata();
- cache.setTotalEntries(node.get(TOTAL_ENTRIES).asInt());
- cache.setHitRatio(node.get(HITRATIO).asDouble());
- cache.setRequestCount(node.get(REQUEST_COUNT).asInt());
- return cache;
- }
-
- public static ModelNode describe(ModelNode node) {
- node.get(TYPE).set(ModelType.OBJECT);
- addAttribute(node, TOTAL_ENTRIES, ModelType.STRING, true);
- addAttribute(node, HITRATIO, ModelType.STRING, true);
- addAttribute(node, REQUEST_COUNT, ModelType.STRING, true);
- return node;
- }
- }
-
- public static class RequestMetadataMapper {
- private static final String TRANSACTION_ID = "transaction-id"; //$NON-NLS-1$
- private static final String NODE_ID = "node-id"; //$NON-NLS-1$
- private static final String SOURCE_REQUEST = "source-request"; //$NON-NLS-1$
- private static final String COMMAND = "command"; //$NON-NLS-1$
- private static final String START_TIME = "start-time"; //$NON-NLS-1$
- private static final String SESSION_ID = "session-id"; //$NON-NLS-1$
- private static final String EXECUTION_ID = "execution-id"; //$NON-NLS-1$
- private static final String STATE = "processing-state"; //$NON-NLS-1$
- private static final String THREAD_STATE = "thread-state"; //$NON-NLS-1$
-
-
- public static ModelNode wrap(RequestMetadata request, ModelNode node) {
- if (request == null) {
- return null;
- }
- node.get(ModelNodeConstants.TYPE).set(ModelType.OBJECT);
-
- node.get(EXECUTION_ID).set(request.getExecutionId());
- node.get(SESSION_ID).set(request.getSessionId());
- node.get(START_TIME).set(request.getStartTime());
- node.get(COMMAND).set(request.getCommand());
- node.get(SOURCE_REQUEST).set(request.sourceRequest());
- if (request.getNodeId() != null) {
- node.get(NODE_ID).set(request.getNodeId());
- }
- if (request.getTransactionId() != null) {
- node.get(TRANSACTION_ID).set(request.getTransactionId());
- }
- node.get(STATE).set(request.getState().name());
- node.get(THREAD_STATE).set(request.getThreadState().name());
- return node;
- }
-
- public static RequestMetadata unwrap(ModelNode node) {
- if (node == null)
- return null;
-
- RequestMetadata request = new RequestMetadata();
- request.setExecutionId(node.get(EXECUTION_ID).asLong());
- request.setSessionId(node.get(SESSION_ID).asString());
- request.setStartTime(node.get(START_TIME).asLong());
- request.setCommand(node.get(COMMAND).asString());
- request.setSourceRequest(node.get(SOURCE_REQUEST).asBoolean());
- if (node.has(NODE_ID)) {
- request.setNodeId(node.get(NODE_ID).asInt());
- }
- if (node.has(TRANSACTION_ID)) {
- request.setTransactionId(node.get(TRANSACTION_ID).asString());
- }
- request.setState(ProcessingState.valueOf(node.get(STATE).asString()));
- request.setThreadState(ThreadState.valueOf(node.get(THREAD_STATE).asString()));
- return request;
- }
-
- public static ModelNode describe(ModelNode node) {
- node.get(TYPE).set(ModelType.OBJECT);
- addAttribute(node, EXECUTION_ID, ModelType.LONG, true);
- addAttribute(node, SESSION_ID, ModelType.STRING, true);
- addAttribute(node, START_TIME, ModelType.LONG, true);
- addAttribute(node, COMMAND, ModelType.STRING, true);
- addAttribute(node, SOURCE_REQUEST, ModelType.BOOLEAN, true);
- addAttribute(node, NODE_ID, ModelType.INT, false);
- addAttribute(node, TRANSACTION_ID, ModelType.STRING, false);
- addAttribute(node, STATE, ModelType.STRING, true);
- addAttribute(node, THREAD_STATE, ModelType.STRING, true);
- return node;
- }
- }
-
- public static class SessionMetadataMapper {
- private static final String SECURITY_DOMAIN = "security-domain"; //$NON-NLS-1$
- private static final String VDB_VERSION = "vdb-version"; //$NON-NLS-1$
- private static final String VDB_NAME = "vdb-name"; //$NON-NLS-1$
- private static final String USER_NAME = "user-name"; //$NON-NLS-1$
- private static final String SESSION_ID = "session-id"; //$NON-NLS-1$
- private static final String LAST_PING_TIME = "last-ping-time"; //$NON-NLS-1$
- private static final String IP_ADDRESS = "ip-address"; //$NON-NLS-1$
- private static final String CLIENT_HOST_NAME = "client-host-address"; //$NON-NLS-1$
- private static final String CREATED_TIME = "created-time"; //$NON-NLS-1$
- private static final String APPLICATION_NAME = "application-name"; //$NON-NLS-1$
- private static final String CLIENT_HARDWARE_ADRESS = "client-hardware-address"; //$NON-NLS-1$
-
-
- public static ModelNode wrap(SessionMetadata session, ModelNode node) {
- if (session == null) {
- return null;
- }
- node.get(ModelNodeConstants.TYPE).set(ModelType.OBJECT);
-
- if (session.getApplicationName() != null) {
- node.get(APPLICATION_NAME).set(session.getApplicationName());
- }
- node.get(CREATED_TIME).set(session.getCreatedTime());
- node.get(CLIENT_HOST_NAME).set(session.getClientHostName());
- node.get(IP_ADDRESS).set(session.getIPAddress());
- node.get(LAST_PING_TIME).set(session.getLastPingTime());
- node.get(SESSION_ID).set(session.getSessionId());
- node.get(USER_NAME).set(session.getUserName());
- node.get(VDB_NAME).set(session.getVDBName());
- node.get(VDB_VERSION).set(session.getVDBVersion());
- if (session.getSecurityDomain() != null){
- node.get(SECURITY_DOMAIN).set(session.getSecurityDomain());
- }
- if (session.getClientHardwareAddress() != null) {
- node.get(CLIENT_HARDWARE_ADRESS).set(session.getClientHardwareAddress());
- }
- return node;
- }
-
- public static SessionMetadata unwrap(ModelNode node) {
- if (node == null)
- return null;
-
- SessionMetadata session = new SessionMetadata();
- if (node.has(APPLICATION_NAME)) {
- session.setApplicationName(node.get(APPLICATION_NAME).asString());
- }
- session.setCreatedTime(node.get(CREATED_TIME).asLong());
- session.setClientHostName(node.get(CLIENT_HOST_NAME).asString());
- session.setIPAddress(node.get(IP_ADDRESS).asString());
- session.setLastPingTime(node.get(LAST_PING_TIME).asLong());
- session.setSessionId(node.get(SESSION_ID).asString());
- session.setUserName(node.get(USER_NAME).asString());
- session.setVDBName(node.get(VDB_NAME).asString());
- session.setVDBVersion(node.get(VDB_VERSION).asInt());
- if (node.has(SECURITY_DOMAIN)) {
- session.setSecurityDomain(node.get(SECURITY_DOMAIN).asString());
- }
- if (node.has(CLIENT_HARDWARE_ADRESS)) {
- session.setClientHardwareAddress(node.get(CLIENT_HARDWARE_ADRESS).asString());
- }
- return session;
- }
-
- public static ModelNode describe(ModelNode node) {
- node.get(TYPE).set(ModelType.OBJECT);
- addAttribute(node, APPLICATION_NAME, ModelType.STRING, false);
- addAttribute(node, CREATED_TIME, ModelType.LONG, true);
- addAttribute(node, CLIENT_HOST_NAME, ModelType.LONG, true);
- addAttribute(node, IP_ADDRESS, ModelType.STRING, true);
- addAttribute(node, LAST_PING_TIME, ModelType.LONG, true);
- addAttribute(node, SESSION_ID, ModelType.STRING, true);
- addAttribute(node, USER_NAME, ModelType.STRING, true);
- addAttribute(node, VDB_NAME, ModelType.STRING, true);
- addAttribute(node, VDB_VERSION, ModelType.INT, true);
- addAttribute(node, SECURITY_DOMAIN, ModelType.STRING, false);
- return node;
- }
- }
-
- public static class TransactionMetadataMapper {
- private static final String ID = "txn-id"; //$NON-NLS-1$
- private static final String SCOPE = "txn-scope"; //$NON-NLS-1$
- private static final String CREATED_TIME = "txn-created-time"; //$NON-NLS-1$
- private static final String ASSOCIATED_SESSION = "session-id"; //$NON-NLS-1$
-
- public static ModelNode wrap(TransactionMetadata object, ModelNode transaction) {
- if (object == null)
- return null;
-
- transaction.get(ModelNodeConstants.TYPE).set(ModelType.OBJECT);
- transaction.get(ASSOCIATED_SESSION).set(object.getAssociatedSession());
- transaction.get(CREATED_TIME).set(object.getCreatedTime());
- transaction.get(SCOPE).set(object.getScope());
- transaction.get(ID).set(object.getId());
-
- return transaction;
- }
-
- public static TransactionMetadata unwrap(ModelNode node) {
- if (node == null)
- return null;
-
- TransactionMetadata transaction = new TransactionMetadata();
- transaction.setAssociatedSession(node.get(ASSOCIATED_SESSION).asString());
- transaction.setCreatedTime(node.get(CREATED_TIME).asLong());
- transaction.setScope(node.get(SCOPE).asString());
- transaction.setId(node.get(ID).asString());
- return transaction;
- }
-
- public static ModelNode describe(ModelNode node) {
- node.get(TYPE).set(ModelType.OBJECT);
- addAttribute(node, ASSOCIATED_SESSION, ModelType.STRING, true);
- addAttribute(node, CREATED_TIME, ModelType.LONG, true);
- addAttribute(node, SCOPE, ModelType.LONG, true);
- addAttribute(node, ID, ModelType.STRING, true);
- return node;
- }
- }
-
- public static class WorkerPoolStatisticsMetadataMapper {
- private static final String MAX_THREADS = "max-threads"; //$NON-NLS-1$
- private static final String HIGHEST_QUEUED = "highest-queued"; //$NON-NLS-1$
- private static final String QUEUED = "queued"; //$NON-NLS-1$
- private static final String QUEUE_NAME = "queue-name"; //$NON-NLS-1$
- private static final String TOTAL_SUBMITTED = "total-submitted"; //$NON-NLS-1$
- private static final String TOTAL_COMPLETED = "total-completed"; //$NON-NLS-1$
- private static final String HIGHEST_ACTIVE_THREADS = "highest-active-threads"; //$NON-NLS-1$
- private static final String ACTIVE_THREADS = "active-threads"; //$NON-NLS-1$
-
-
- public static ModelNode wrap(WorkerPoolStatisticsMetadata stats, ModelNode node) {
- if (stats == null)
- return null;
- node.get(ModelNodeConstants.TYPE).set(ModelType.OBJECT);
-
- node.get(ACTIVE_THREADS).set(stats.getActiveThreads());
- node.get(HIGHEST_ACTIVE_THREADS).set(stats.getHighestActiveThreads());
- node.get(TOTAL_COMPLETED).set(stats.getTotalCompleted());
- node.get(TOTAL_SUBMITTED).set(stats.getTotalSubmitted());
- node.get(QUEUE_NAME).set(stats.getQueueName());
- node.get(QUEUED).set(stats.getQueued());
- node.get(HIGHEST_QUEUED).set(stats.getHighestQueued());
- node.get(MAX_THREADS).set(stats.getMaxThreads());
-
- return node;
- }
-
- public static WorkerPoolStatisticsMetadata unwrapMetaValue(ModelNode node) {
- if (node == null)
- return null;
-
- WorkerPoolStatisticsMetadata stats = new WorkerPoolStatisticsMetadata();
- stats.setActiveThreads(node.get(ACTIVE_THREADS).asInt());
- stats.setHighestActiveThreads(node.get(HIGHEST_ACTIVE_THREADS).asInt());
- stats.setTotalCompleted(node.get(TOTAL_COMPLETED).asLong());
- stats.setTotalSubmitted(node.get(TOTAL_SUBMITTED).asLong());
- stats.setQueueName(node.get(QUEUE_NAME).asString());
- stats.setQueued(node.get(QUEUED).asInt());
- stats.setHighestQueued(node.get(HIGHEST_QUEUED).asInt());
- stats.setMaxThreads(node.get(MAX_THREADS).asInt());
- return stats;
- }
-
- public static ModelNode describe(ModelNode node) {
- node.get(TYPE).set(ModelType.OBJECT);
- addAttribute(node, ACTIVE_THREADS, ModelType.INT, true);
- addAttribute(node, HIGHEST_ACTIVE_THREADS, ModelType.INT, true);
- addAttribute(node, TOTAL_COMPLETED, ModelType.LONG, true);
- addAttribute(node, TOTAL_SUBMITTED, ModelType.LONG, true);
- addAttribute(node, QUEUE_NAME, ModelType.STRING, true);
- addAttribute(node, QUEUED, ModelType.INT, true);
- addAttribute(node, HIGHEST_QUEUED, ModelType.INT, true);
- addAttribute(node, MAX_THREADS, ModelType.INT, true);
- return node;
- }
- }
-
- private static final String CHILDREN = "children"; //$NON-NLS-1$
- private static final String ATTRIBUTES = "attributes"; //$NON-NLS-1$
- private static final String DOT_DESC = ".describe"; //$NON-NLS-1$
- private static final String TYPE = "type"; //$NON-NLS-1$
- private static final String MIN_OCCURS = "min-occurs"; //$NON-NLS-1$
- private static final String REQUIRED = "required"; //$NON-NLS-1$
- private static final String ALLOWED = "allowed"; //$NON-NLS-1$
- static ModelNode addAttribute(ModelNode node, String name, ModelType dataType, boolean required) {
- node.get(ATTRIBUTES, name, TYPE).set(dataType);
- node.get(ATTRIBUTES, name, DESCRIPTION).set(AdminPlugin.Util.getString(name+DOT_DESC));
- node.get(ATTRIBUTES, name, REQUIRED).set(required);
- return node;
- }
+public interface MetadataMapper<T> {
+ ModelNode wrap(T obj, ModelNode node);
+ T unwrap(ModelNode node);
+ ModelNode describe(ModelNode node);
}
-
-
Modified: branches/as7/admin/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java
===================================================================
--- branches/as7/admin/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/admin/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -153,6 +153,10 @@
public List<SourceMappingMetadata> getSourceMappings(){
return new ArrayList<SourceMappingMetadata>(this.sources.getMap().values());
}
+
+ public SourceMappingMetadata getSourceMapping(String sourceName){
+ return this.sources.getMap().get(sourceName);
+ }
public void setSourceMappings(List<SourceMappingMetadata> sources){
for (SourceMappingMetadata source: sources) {
Copied: branches/as7/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataMapper.java (from rev 3450, branches/as7/admin/src/main/java/org/teiid/adminapi/impl/MetadataMapper.java)
===================================================================
--- branches/as7/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataMapper.java (rev 0)
+++ branches/as7/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataMapper.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -0,0 +1,1114 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.adminapi.impl;
+
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.dmr.ModelNode;
+import org.jboss.dmr.ModelType;
+import org.teiid.adminapi.AdminPlugin;
+import org.teiid.adminapi.DataPolicy;
+import org.teiid.adminapi.Model;
+import org.teiid.adminapi.Translator;
+import org.teiid.adminapi.Request.ProcessingState;
+import org.teiid.adminapi.Request.ThreadState;
+import org.teiid.adminapi.VDB.ConnectionType;
+import org.teiid.adminapi.VDB.Status;
+import org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData;
+import org.teiid.adminapi.impl.ModelMetaData.ValidationError;
+
+public class VDBMetadataMapper implements MetadataMapper<VDBMetaData> {
+ private static final String VDBNAME = "vdb-name"; //$NON-NLS-1$
+ private static final String CONNECTIONTYPE = "connection-type"; //$NON-NLS-1$
+ private static final String STATUS = "status"; //$NON-NLS-1$
+ private static final String VERSION = "vdb-version"; //$NON-NLS-1$
+ private static final String URL = "url"; //$NON-NLS-1$
+ private static final String MODELS = "models"; //$NON-NLS-1$
+ private static final String OVERRIDE_TRANSLATORS = "override-translators"; //$NON-NLS-1$
+ private static final String DESCRIPTION = "description"; //$NON-NLS-1$
+ private static final String PROPERTIES = "properties"; //$NON-NLS-1$
+ private static final String DYNAMIC = "dynamic"; //$NON-NLS-1$
+ private static final String DATA_POLICIES = "data-policies"; //$NON-NLS-1$
+
+ public static VDBMetadataMapper INSTANCE = new VDBMetadataMapper();
+
+ public ModelNode wrap(VDBMetaData vdb, ModelNode node) {
+ if (vdb == null) {
+ return null;
+ }
+ node.get(ModelNodeConstants.TYPE).set(ModelType.OBJECT);
+
+ node.get(VDBNAME).set(vdb.getName());
+ node.get(CONNECTIONTYPE).set(vdb.getConnectionType().toString());
+ node.get(STATUS).set(vdb.getStatus().toString());
+ node.get(VERSION).set(vdb.getVersion());
+ if (vdb.getUrl() != null) {
+ }
+ if (vdb.getDescription() != null) {
+ node.get(DESCRIPTION).set(vdb.getDescription());
+ }
+ node.get(DYNAMIC).set(vdb.isDynamic());
+
+ //PROPERTIES
+ List<PropertyMetadata> properties = vdb.getJAXBProperties();
+ if (properties!= null && !properties.isEmpty()) {
+ ModelNode propsNode = node.get(CHILDREN, PROPERTIES);
+ for (PropertyMetadata prop:properties) {
+ propsNode.add(PropertyMetaDataMapper.INSTANCE.wrap(prop, new ModelNode()));
+ }
+ }
+
+ // MODELS
+ Map<String, ModelMetaData> models = vdb.getModelMetaDatas();
+ if (models != null && !models.isEmpty()) {
+ ModelNode modelNodes = node.get(CHILDREN, MODELS);
+ for(ModelMetaData model:models.values()) {
+ modelNodes.add(ModelMetadataMapper.INSTANCE.wrap(model, new ModelNode()));
+ }
+ }
+
+ // OVERRIDE_TRANSLATORS
+ List<Translator> translators = vdb.getOverrideTranslators();
+ if (translators != null && !translators.isEmpty()) {
+ ModelNode translatorNodes = node.get(CHILDREN, OVERRIDE_TRANSLATORS);
+ for (Translator translator:translators) {
+ translatorNodes.add(VDBTranslatorMetaDataMapper.INSTANCE.wrap((VDBTranslatorMetaData)translator, new ModelNode()));
+ }
+ }
+
+ // DATA_POLICIES
+ List<DataPolicy> policies = vdb.getDataPolicies();
+ if (policies != null && !policies.isEmpty()) {
+ ModelNode dataPoliciesNodes = node.get(CHILDREN, DATA_POLICIES);
+ for (DataPolicy policy:policies) {
+ dataPoliciesNodes.add(DataPolicyMetadataMapper.INSTANCE.wrap((DataPolicyMetadata)policy, new ModelNode()));
+ }
+ }
+ return node;
+ }
+
+ public VDBMetaData unwrap(ModelNode node) {
+ if (node == null)
+ return null;
+
+ VDBMetaData vdb = new VDBMetaData();
+ if (node.has(VDBNAME)) {
+ vdb.setName(node.get(VDBNAME).asString());
+ }
+ if (node.has(CONNECTIONTYPE)) {
+ vdb.setConnectionType(node.get(CONNECTIONTYPE).asString());
+ }
+ if (node.has(STATUS)) {
+ vdb.setStatus(node.get(STATUS).asString());
+ }
+ if (node.has(VERSION)) {
+ vdb.setVersion(node.get(VERSION).asInt());
+ }
+ if (node.has(URL)) {
+ vdb.setUrl(node.get(URL).asString());
+ }
+ if(node.has(DESCRIPTION)) {
+ vdb.setDescription(node.get(DESCRIPTION).asString());
+ }
+ if (node.has(DYNAMIC)) {
+ vdb.setDynamic(node.get(DYNAMIC).asBoolean());
+ }
+
+ //PROPERTIES
+ if (node.get(CHILDREN, PROPERTIES).isDefined()) {
+ List<ModelNode> propNodes = node.get(CHILDREN, PROPERTIES).asList();
+ for (ModelNode propNode:propNodes) {
+ PropertyMetadata prop = PropertyMetaDataMapper.INSTANCE.unwrap(propNode);
+ if (prop != null) {
+ vdb.addProperty(prop.getName(), prop.getValue());
+ }
+ }
+ }
+
+ // MODELS
+ if (node.get(CHILDREN, MODELS).isDefined()) {
+ List<ModelNode> modelNodes = node.get(CHILDREN, MODELS).asList();
+ for(ModelNode modelNode:modelNodes) {
+ ModelMetaData model = ModelMetadataMapper.INSTANCE.unwrap(modelNode);
+ if (model != null) {
+ vdb.addModel(model);
+ }
+ }
+ }
+
+ // OVERRIDE_TRANSLATORS
+ if (node.get(CHILDREN, OVERRIDE_TRANSLATORS).isDefined()) {
+ List<ModelNode> translatorNodes = node.get(CHILDREN, OVERRIDE_TRANSLATORS).asList();
+ for (ModelNode translatorNode:translatorNodes) {
+ VDBTranslatorMetaData translator = VDBTranslatorMetaDataMapper.INSTANCE.unwrap(translatorNode);
+ if (translator != null) {
+ vdb.addOverideTranslator(translator);
+ }
+ }
+ }
+
+ // DATA_POLICIES
+ if (node.get(CHILDREN, DATA_POLICIES).isDefined()) {
+ List<ModelNode> policiesNodes = node.get(CHILDREN, DATA_POLICIES).asList();
+ for (ModelNode policyNode:policiesNodes) {
+ DataPolicyMetadata policy = DataPolicyMetadataMapper.INSTANCE.unwrap(policyNode);
+ if (policy != null) {
+ vdb.addDataPolicy(policy);
+ }
+
+ }
+ }
+ return vdb;
+ }
+
+ public ModelNode describe(ModelNode node) {
+ node.get(TYPE).set(ModelType.OBJECT);
+ addAttribute(node, VDBNAME, ModelType.STRING, true);
+
+ ModelNode connectionsAllowed = new ModelNode();
+ connectionsAllowed.add(ConnectionType.NONE.toString());
+ connectionsAllowed.add(ConnectionType.ANY.toString());
+ connectionsAllowed.add(ConnectionType.BY_VERSION.toString());
+ addAttribute(node, CONNECTIONTYPE, ModelType.STRING, false).get(ALLOWED).set(connectionsAllowed);
+
+ ModelNode statusAllowed = new ModelNode();
+ statusAllowed.add(Status.ACTIVE.toString());
+ statusAllowed.add(Status.INACTIVE.toString());
+ addAttribute(node, STATUS, ModelType.STRING, true).get(ALLOWED).set(statusAllowed);
+
+ addAttribute(node, VERSION, ModelType.INT, true);
+ addAttribute(node, URL, ModelType.STRING, false);
+ addAttribute(node, DESCRIPTION, ModelType.STRING, false);
+ addAttribute(node, DYNAMIC, ModelType.BOOLEAN, false);
+
+ ModelNode props = node.get(CHILDREN, PROPERTIES);
+ props.get(DESCRIPTION).set(AdminPlugin.Util.getString(PROPERTIES+DOT_DESC));
+ PropertyMetaDataMapper.INSTANCE.describe(props);
+
+ ModelNode models = node.get(CHILDREN, MODELS);
+ ModelMetadataMapper.INSTANCE.describe(models);
+ models.get(DESCRIPTION).set(AdminPlugin.Util.getString(MODELS+DOT_DESC));
+ models.get(MIN_OCCURS).set(1);
+
+ ModelNode translators = node.get(CHILDREN, OVERRIDE_TRANSLATORS);
+ translators.get(DESCRIPTION).set(AdminPlugin.Util.getString(OVERRIDE_TRANSLATORS+DOT_DESC));
+ VDBTranslatorMetaDataMapper.INSTANCE.describe(translators);
+
+ ModelNode dataPolicies = node.get(CHILDREN, DATA_POLICIES);
+ dataPolicies.get(DESCRIPTION).set(AdminPlugin.Util.getString(DATA_POLICIES+DOT_DESC));
+ DataPolicyMetadataMapper.INSTANCE.describe(dataPolicies);
+ return node;
+ }
+
+ /**
+ * model metadata mapper
+ */
+ public static class ModelMetadataMapper implements MetadataMapper<ModelMetaData>{
+ private static final String MODEL_NAME = "model-name"; //$NON-NLS-1$
+ private static final String DESCRIPTION = "description"; //$NON-NLS-1$
+ private static final String VISIBLE = "visible"; //$NON-NLS-1$
+ private static final String MODEL_TYPE = "model-type"; //$NON-NLS-1$
+ private static final String MODELPATH = "model-path"; //$NON-NLS-1$
+ private static final String PROPERTIES = "properties"; //$NON-NLS-1$
+ private static final String SOURCE_MAPPINGS = "source-mappings"; //$NON-NLS-1$
+ private static final String VALIDITY_ERRORS = "validity-errors"; //$NON-NLS-1$
+
+ public static ModelMetadataMapper INSTANCE = new ModelMetadataMapper();
+
+ public ModelNode wrap(ModelMetaData model, ModelNode node) {
+ if (model == null) {
+ return null;
+ }
+ node.get(TYPE).set(ModelType.OBJECT);
+
+ node.get(MODEL_NAME).set(model.getName());
+ if (model.getDescription() != null) {
+ node.get(DESCRIPTION).set(model.getDescription());
+ }
+ node.get(VISIBLE).set(model.isVisible());
+ node.get(MODEL_TYPE).set(model.getModelType().toString());
+ if (model.getPath() != null) {
+ node.get(MODELPATH).set(model.getPath());
+ }
+
+ List<PropertyMetadata> properties = model.getJAXBProperties();
+ if (properties!= null && !properties.isEmpty()) {
+ ModelNode propsNode = node.get(CHILDREN, PROPERTIES);
+ for (PropertyMetadata prop:properties) {
+ propsNode.add(PropertyMetaDataMapper.INSTANCE.wrap(prop, new ModelNode()));
+ }
+ }
+
+ List<SourceMappingMetadata> sources = model.getSourceMappings();
+ if (sources != null && !sources.isEmpty()) {
+ ModelNode sourceMappingNode = node.get(CHILDREN, SOURCE_MAPPINGS);
+ for(SourceMappingMetadata source:sources) {
+ sourceMappingNode.add(SourceMappingMetadataMapper.INSTANCE.wrap(source, new ModelNode()));
+ }
+ }
+
+ List<ValidationError> errors = model.getErrors();
+ if (errors != null && !errors.isEmpty()) {
+ ModelNode errorsNode = node.get(CHILDREN, VALIDITY_ERRORS);
+ for (ValidationError error:errors) {
+ errorsNode.add(ValidationErrorMapper.INSTANCE.wrap(error, new ModelNode()));
+ }
+ }
+ return node;
+ }
+
+ public ModelMetaData unwrap(ModelNode node) {
+ if (node == null) {
+ return null;
+ }
+
+ ModelMetaData model = new ModelMetaData();
+ if (node.has(MODEL_NAME)) {
+ model.setName(node.get(MODEL_NAME).asString());
+ }
+ if (node.has(DESCRIPTION)) {
+ model.setDescription(node.get(DESCRIPTION).asString());
+ }
+ if (node.has(VISIBLE)) {
+ model.setVisible(node.get(VISIBLE).asBoolean());
+ }
+ if(node.has(MODEL_TYPE)) {
+ model.setModelType(node.get(MODEL_TYPE).asString());
+ }
+ if(node.has(MODELPATH)) {
+ model.setPath(node.get(MODELPATH).asString());
+ }
+
+ if (node.get(CHILDREN, PROPERTIES).isDefined()) {
+ List<ModelNode> propNodes = node.get(CHILDREN, PROPERTIES).asList();
+ for (ModelNode propNode:propNodes) {
+ PropertyMetadata prop = PropertyMetaDataMapper.INSTANCE.unwrap(propNode);
+ if (prop != null) {
+ model.addProperty(prop.getName(), prop.getValue());
+ }
+ }
+ }
+
+ if (node.get(CHILDREN, SOURCE_MAPPINGS).isDefined()) {
+ List<ModelNode> sourceMappingNodes = node.get(CHILDREN, SOURCE_MAPPINGS).asList();
+ for (ModelNode sourceMapping:sourceMappingNodes) {
+ SourceMappingMetadata source = SourceMappingMetadataMapper.INSTANCE.unwrap(sourceMapping);
+ if (source != null) {
+ model.addSourceMapping(source);
+ }
+ }
+ }
+
+ if (node.get(CHILDREN, VALIDITY_ERRORS).isDefined()) {
+ List<ModelNode> errorNodes = node.get(CHILDREN, VALIDITY_ERRORS).asList();
+ for(ModelNode errorNode:errorNodes) {
+ ValidationError error = ValidationErrorMapper.INSTANCE.unwrap(errorNode);
+ if (error != null) {
+ model.addError(error);
+ }
+ }
+ }
+ return model;
+ }
+
+ public ModelNode describe(ModelNode node) {
+ node.get(TYPE).set(ModelType.OBJECT);
+
+ ModelNode modelTypes = new ModelNode();
+ modelTypes.add(Model.Type.PHYSICAL.toString());
+ modelTypes.add(Model.Type.VIRTUAL.toString());
+ modelTypes.add(Model.Type.FUNCTION.toString());
+ modelTypes.add(Model.Type.OTHER.toString());
+ addAttribute(node, MODEL_NAME, ModelType.STRING, true).get(ALLOWED).set(modelTypes);
+
+ addAttribute(node, DESCRIPTION, ModelType.STRING, false);
+ addAttribute(node, VISIBLE, ModelType.BOOLEAN, false);
+ addAttribute(node, MODEL_TYPE, ModelType.STRING, true);
+ addAttribute(node, MODELPATH, ModelType.STRING, false);
+
+ ModelNode props = node.get(CHILDREN, PROPERTIES);
+ props.get(DESCRIPTION).set(AdminPlugin.Util.getString(PROPERTIES+DOT_DESC));
+ PropertyMetaDataMapper.INSTANCE.describe(props);
+
+ ModelNode source = node.get(CHILDREN, SOURCE_MAPPINGS);
+ source.get(DESCRIPTION).set(AdminPlugin.Util.getString(SOURCE_MAPPINGS+DOT_DESC));
+ SourceMappingMetadataMapper.INSTANCE.describe(source);
+
+ ModelNode errors = node.get(CHILDREN, VALIDITY_ERRORS);
+ errors.get(DESCRIPTION).set(AdminPlugin.Util.getString(VALIDITY_ERRORS+DOT_DESC));
+ ValidationErrorMapper.INSTANCE.describe(errors);
+
+ return node;
+ }
+ }
+
+ /**
+ * validation error mapper
+ */
+ public static class ValidationErrorMapper implements MetadataMapper<ValidationError>{
+ private static final String ERROR_PATH = "error-path"; //$NON-NLS-1$
+ private static final String SEVERITY = "severity"; //$NON-NLS-1$
+ private static final String MESSAGE = "message"; //$NON-NLS-1$
+
+
+ public static ValidationErrorMapper INSTANCE = new ValidationErrorMapper();
+
+ public ModelNode wrap(ValidationError error, ModelNode node) {
+ if (error == null) {
+ return null;
+ }
+
+ node.get(TYPE).set(ModelType.OBJECT);
+ if (error.getPath() != null) {
+ node.get(ERROR_PATH).set(error.getPath());
+ }
+ node.get(SEVERITY).set(error.getSeverity());
+ node.get(MESSAGE).set(error.getValue());
+
+ return node;
+ }
+
+ public ValidationError unwrap(ModelNode node) {
+ if (node == null) {
+ return null;
+ }
+
+ ValidationError error = new ValidationError();
+ if (node.has(ERROR_PATH)) {
+ error.setPath(node.get(ERROR_PATH).asString());
+ }
+ if (node.has(SEVERITY)) {
+ error.setSeverity(node.get(SEVERITY).asString());
+ }
+ if(node.has(MESSAGE)) {
+ error.setValue(node.get(MESSAGE).asString());
+ }
+ return error;
+ }
+
+ public ModelNode describe(ModelNode node) {
+ node.get(TYPE).set(ModelType.OBJECT);
+ addAttribute(node, ERROR_PATH, ModelType.STRING, false);
+ addAttribute(node, SEVERITY, ModelType.STRING, true);
+ addAttribute(node, MESSAGE, ModelType.STRING, true);
+ return node;
+ }
+ }
+
+ /**
+ * Source Mapping Metadata mapper
+ */
+ public static class SourceMappingMetadataMapper implements MetadataMapper<SourceMappingMetadata>{
+ private static final String SOURCE_NAME = "source-name"; //$NON-NLS-1$
+ private static final String JNDI_NAME = "jndi-name"; //$NON-NLS-1$
+ private static final String TRANSLATOR_NAME = "translator-name"; //$NON-NLS-1$
+
+ public static SourceMappingMetadataMapper INSTANCE = new SourceMappingMetadataMapper();
+
+ public ModelNode wrap(SourceMappingMetadata source, ModelNode node) {
+ if (source == null) {
+ return null;
+ }
+
+ node.get(TYPE).set(ModelType.OBJECT);
+
+ node.get(SOURCE_NAME).set(source.getName());
+ node.get(JNDI_NAME).set(source.getConnectionJndiName());
+ node.get(TRANSLATOR_NAME).set(source.getTranslatorName());
+ return node;
+ }
+
+ public SourceMappingMetadata unwrap(ModelNode node) {
+ if (node == null) {
+ return null;
+ }
+ SourceMappingMetadata source = new SourceMappingMetadata();
+ if (node.has(SOURCE_NAME)) {
+ source.setName(node.get(SOURCE_NAME).asString());
+ }
+ if (node.has(JNDI_NAME)) {
+ source.setConnectionJndiName(node.get(JNDI_NAME).asString());
+ }
+ if (node.has(TRANSLATOR_NAME)) {
+ source.setTranslatorName(node.get(TRANSLATOR_NAME).asString());
+ }
+ return source;
+ }
+
+ public ModelNode describe(ModelNode node) {
+ node.get(TYPE).set(ModelType.OBJECT);
+ addAttribute(node, SOURCE_NAME, ModelType.STRING, true);
+ addAttribute(node, JNDI_NAME, ModelType.STRING, true);
+ addAttribute(node, TRANSLATOR_NAME, ModelType.STRING, true);
+ return node;
+ }
+ }
+
+ /**
+ * Source Mapping Metadata mapper
+ */
+ public static class VDBTranslatorMetaDataMapper implements MetadataMapper<VDBTranslatorMetaData>{
+ private static final String TRANSLATOR_NAME = "translator-name"; //$NON-NLS-1$
+ private static final String BASETYPE = "base-type"; //$NON-NLS-1$
+ private static final String DESCRIPTION = "description"; //$NON-NLS-1$
+ private static final String PROPERTIES = "properties"; //$NON-NLS-1$
+ private static final String MODULE_NAME = "module-name"; //$NON-NLS-1$
+
+
+ public static VDBTranslatorMetaDataMapper INSTANCE = new VDBTranslatorMetaDataMapper();
+
+ public ModelNode wrap(VDBTranslatorMetaData translator, ModelNode node) {
+ if (translator == null) {
+ return null;
+ }
+ node.get(TYPE).set(ModelType.OBJECT);
+
+ node.get(TRANSLATOR_NAME).set(translator.getName());
+ if (translator.getType() != null) {
+ node.get(BASETYPE).set(translator.getType());
+ }
+ if (translator.getDescription() != null) {
+ node.get(DESCRIPTION).set(translator.getDescription());
+ }
+
+ if (translator.getModuleName() != null) {
+ node.get(MODULE_NAME).set(translator.getModuleName());
+ }
+
+ List<PropertyMetadata> properties = translator.getJAXBProperties();
+ if (properties!= null && !properties.isEmpty()) {
+ ModelNode propsNode = node.get(CHILDREN, PROPERTIES);
+ for (PropertyMetadata prop:properties) {
+ propsNode.add(PropertyMetaDataMapper.INSTANCE.wrap(prop, new ModelNode()));
+ }
+ }
+ return node;
+ }
+
+ public VDBTranslatorMetaData unwrap(ModelNode node) {
+ if (node == null) {
+ return null;
+ }
+ VDBTranslatorMetaData translator = new VDBTranslatorMetaData();
+ if (node.has(TRANSLATOR_NAME)) {
+ translator.setName(node.get(TRANSLATOR_NAME).asString());
+ }
+ if (node.has(BASETYPE)) {
+ translator.setType(node.get(BASETYPE).asString());
+ }
+ if (node.has(DESCRIPTION)) {
+ translator.setDescription(node.get(DESCRIPTION).asString());
+ }
+ if (node.has(MODULE_NAME)) {
+ translator.setModuleName(node.get(MODULE_NAME).asString());
+ }
+
+ if (node.get(CHILDREN,PROPERTIES).isDefined()) {
+ List<ModelNode> propNodes = node.get(CHILDREN, PROPERTIES).asList();
+ for (ModelNode propNode:propNodes) {
+ PropertyMetadata prop = PropertyMetaDataMapper.INSTANCE.unwrap(propNode);
+ if (prop != null) {
+ translator.addProperty(prop.getName(), prop.getValue());
+ }
+ }
+ }
+ return translator;
+ }
+
+ public ModelNode describe(ModelNode node) {
+ node.get(TYPE).set(ModelType.OBJECT);
+ addAttribute(node, TRANSLATOR_NAME, ModelType.STRING, true);
+ addAttribute(node, BASETYPE, ModelType.STRING, true);
+ addAttribute(node, DESCRIPTION, ModelType.STRING, false);
+ addAttribute(node, MODULE_NAME, ModelType.STRING, false);
+
+ ModelNode props = node.get(CHILDREN, PROPERTIES);
+ props.get(DESCRIPTION).set(AdminPlugin.Util.getString(PROPERTIES+DOT_DESC));
+ PropertyMetaDataMapper.INSTANCE.describe(props);
+ return node;
+ }
+ }
+
+ /**
+ * Property Metadata mapper
+ */
+ public static class PropertyMetaDataMapper implements MetadataMapper<PropertyMetadata>{
+ private static final String PROPERTY_NAME = "property-name"; //$NON-NLS-1$
+ private static final String PROPERTY_VALUE = "property-value"; //$NON-NLS-1$
+
+ public static PropertyMetaDataMapper INSTANCE = new PropertyMetaDataMapper();
+
+ public ModelNode wrap(PropertyMetadata property, ModelNode node) {
+ if (property == null) {
+ return null;
+ }
+ node.get(ModelNodeConstants.TYPE).set(ModelType.OBJECT);
+
+ node.get(PROPERTY_NAME).set(property.getName());
+ node.get(PROPERTY_VALUE).set(property.getValue());
+
+ return node;
+ }
+
+ public PropertyMetadata unwrap(ModelNode node) {
+ if(node == null) {
+ return null;
+ }
+ PropertyMetadata property = new PropertyMetadata();
+ if (node.has(PROPERTY_NAME)) {
+ property.setName(node.get(PROPERTY_NAME).asString());
+ }
+ if(node.has(PROPERTY_VALUE)) {
+ property.setValue(node.get(PROPERTY_VALUE).asString());
+ }
+ return property;
+ }
+
+ public ModelNode describe(ModelNode node) {
+ node.get(TYPE).set(ModelType.OBJECT);
+ addAttribute(node, PROPERTY_NAME, ModelType.STRING, true);
+ addAttribute(node, PROPERTY_VALUE, ModelType.STRING, true);
+ return node;
+ }
+ }
+
+ /**
+ * DataPolicy Metadata mapper
+ */
+ public static class DataPolicyMetadataMapper implements MetadataMapper<DataPolicyMetadata>{
+ private static final String POLICY_NAME = "policy-name"; //$NON-NLS-1$
+ private static final String DATA_PERMISSIONS = "data-permissions"; //$NON-NLS-1$
+ private static final String MAPPED_ROLE_NAMES = "mapped-role-names"; //$NON-NLS-1$
+ private static final String ALLOW_CREATE_TEMP_TABLES = "allow-create-temp-tables"; //$NON-NLS-1$
+ private static final String ANY_AUTHENTICATED = "any-authenticated"; //$NON-NLS-1$
+ private static final String ALLOW_CREATE = "allow-create"; //$NON-NLS-1$
+ private static final String ALLOW_READ = "allow-read"; //$NON-NLS-1$
+ private static final String ALLOW_UPDATE = "allow-update"; //$NON-NLS-1$
+ private static final String ALLOW_DELETE = "allow-delete"; //$NON-NLS-1$
+ private static final String ALLOW_EXECUTE = "allow-execute"; //$NON-NLS-1$
+ private static final String ALLOW_ALTER= "allow-alter"; //$NON-NLS-1$
+
+ public static DataPolicyMetadataMapper INSTANCE = new DataPolicyMetadataMapper();
+
+ public ModelNode wrap(DataPolicyMetadata policy, ModelNode node) {
+ if (policy == null) {
+ return null;
+ }
+ node.get(ModelNodeConstants.TYPE).set(ModelType.OBJECT);
+
+ node.get(POLICY_NAME).set(policy.getName());
+ if (policy.getDescription() != null) {
+ node.get(DESCRIPTION).set(policy.getDescription());
+ }
+ if (policy.isAllowCreateTemporaryTables() != null) {
+ node.get(ALLOW_CREATE_TEMP_TABLES).set(policy.isAllowCreateTemporaryTables());
+ }
+ node.get(ANY_AUTHENTICATED).set(policy.isAnyAuthenticated());
+
+ //DATA_PERMISSIONS
+ List<DataPolicy.DataPermission> permissions = policy.getPermissions();
+ if (permissions != null && !permissions.isEmpty()) {
+ ModelNode permissionNodes = node.get(CHILDREN, DATA_PERMISSIONS);
+ for (DataPolicy.DataPermission dataPermission:permissions) {
+ permissionNodes.add(PermissionMetaDataMapper.INSTANCE.wrap((PermissionMetaData)dataPermission, new ModelNode()));
+ }
+ }
+
+ //MAPPED_ROLE_NAMES
+ if (policy.getMappedRoleNames() != null && !policy.getMappedRoleNames().isEmpty()) {
+ ModelNode mappedRoleNodes = node.get(CHILDREN, MAPPED_ROLE_NAMES);
+ for (String role:policy.getMappedRoleNames()) {
+ mappedRoleNodes.add(role);
+ }
+ }
+ return node;
+ }
+
+ public DataPolicyMetadata unwrap(ModelNode node) {
+ if(node == null) {
+ return null;
+ }
+ DataPolicyMetadata policy = new DataPolicyMetadata();
+ if (node.has(POLICY_NAME)) {
+ policy.setName(node.get(POLICY_NAME).asString());
+ }
+ if (node.has(DESCRIPTION)) {
+ policy.setDescription(node.get(DESCRIPTION).asString());
+ }
+ if (node.has(ALLOW_CREATE_TEMP_TABLES)) {
+ policy.setAllowCreateTemporaryTables(node.get(ALLOW_CREATE_TEMP_TABLES).asBoolean());
+ }
+ if (node.has(ANY_AUTHENTICATED)) {
+ policy.setAnyAuthenticated(node.get(ANY_AUTHENTICATED).asBoolean());
+ }
+
+ //DATA_PERMISSIONS
+ if (node.get(CHILDREN, DATA_PERMISSIONS).isDefined()) {
+ List<ModelNode> permissionNodes = node.get(CHILDREN, DATA_PERMISSIONS).asList();
+ for (ModelNode permissionNode:permissionNodes) {
+ PermissionMetaData permission = PermissionMetaDataMapper.INSTANCE.unwrap(permissionNode);
+ if (permission != null) {
+ policy.addPermission(permission);
+ }
+ }
+ }
+
+ //MAPPED_ROLE_NAMES
+ if (node.get(CHILDREN, MAPPED_ROLE_NAMES).isDefined()) {
+ List<ModelNode> roleNameNodes = node.get(CHILDREN, MAPPED_ROLE_NAMES).asList();
+ for (ModelNode roleNameNode:roleNameNodes) {
+ policy.addMappedRoleName(roleNameNode.asString());
+ }
+ }
+ return policy;
+ }
+
+ public ModelNode describe(ModelNode node) {
+ node.get(TYPE).set(ModelType.OBJECT);
+ addAttribute(node, POLICY_NAME, ModelType.STRING, true);
+ addAttribute(node, DESCRIPTION, ModelType.STRING, false);
+ addAttribute(node, ALLOW_CREATE_TEMP_TABLES, ModelType.BOOLEAN, false);
+ addAttribute(node, ANY_AUTHENTICATED, ModelType.BOOLEAN, false);
+
+ ModelNode permissions = node.get(CHILDREN, DATA_PERMISSIONS);
+ permissions.get(DESCRIPTION).set(AdminPlugin.Util.getString(DATA_PERMISSIONS+DOT_DESC));
+ permissions.get(MIN_OCCURS).set(1);
+
+ ModelNode create = permissions.get(CHILDREN, ALLOW_CREATE);
+ create.get(DESCRIPTION).set(AdminPlugin.Util.getString(ALLOW_CREATE+DOT_DESC));
+
+ ModelNode read = permissions.get(CHILDREN, ALLOW_READ);
+ read.get(DESCRIPTION).set(AdminPlugin.Util.getString(ALLOW_READ+DOT_DESC));
+
+ ModelNode update = permissions.get(CHILDREN, ALLOW_UPDATE);
+ update.get(DESCRIPTION).set(AdminPlugin.Util.getString(ALLOW_UPDATE+DOT_DESC));
+
+ ModelNode delete = permissions.get(CHILDREN, ALLOW_DELETE);
+ delete.get(DESCRIPTION).set(AdminPlugin.Util.getString(ALLOW_DELETE+DOT_DESC));
+
+ ModelNode execute = permissions.get(CHILDREN, ALLOW_EXECUTE);
+ execute.get(DESCRIPTION).set(AdminPlugin.Util.getString(ALLOW_EXECUTE+DOT_DESC));
+
+ ModelNode alter = permissions.get(CHILDREN, ALLOW_ALTER);
+ alter.get(DESCRIPTION).set(AdminPlugin.Util.getString(ALLOW_ALTER+DOT_DESC));
+
+ ModelNode roleNames = node.get(CHILDREN, MAPPED_ROLE_NAMES);
+ roleNames.get(TYPE).set(ModelType.LIST);
+ roleNames.get(DESCRIPTION).set(AdminPlugin.Util.getString(MAPPED_ROLE_NAMES+DOT_DESC));
+ roleNames.get("value-type").set(ModelType.STRING); //$NON-NLS-1$
+ return node;
+ }
+ }
+
+ public static class PermissionMetaDataMapper implements MetadataMapper<PermissionMetaData>{
+ private static final String RESOURCE_NAME = "resource-name"; //$NON-NLS-1$
+ private static final String ALLOW_CREATE = "allow-create"; //$NON-NLS-1$
+ private static final String ALLOW_DELETE = "allow-delete"; //$NON-NLS-1$
+ private static final String ALLOW_UPADTE = "allow-update"; //$NON-NLS-1$
+ private static final String ALLOW_READ = "allow-read"; //$NON-NLS-1$
+ private static final String ALLOW_EXECUTE = "allow-execute"; //$NON-NLS-1$
+ private static final String ALLOW_ALTER = "allow-alter"; //$NON-NLS-1$
+
+ public static PermissionMetaDataMapper INSTANCE = new PermissionMetaDataMapper();
+
+ public ModelNode wrap(PermissionMetaData permission, ModelNode node) {
+ if (permission == null) {
+ return null;
+ }
+
+ node.get(ModelNodeConstants.TYPE).set(ModelType.OBJECT);
+
+ node.get(RESOURCE_NAME).set(permission.getResourceName());
+ if (permission.getAllowCreate() != null) {
+ node.get(ALLOW_CREATE).set(permission.getAllowCreate().booleanValue());
+ }
+ if (permission.getAllowDelete() != null) {
+ node.get(ALLOW_DELETE).set(permission.getAllowDelete().booleanValue());
+ }
+ if (permission.getAllowUpdate() != null) {
+ node.get(ALLOW_UPADTE).set(permission.getAllowUpdate().booleanValue());
+ }
+ if (permission.getAllowRead() != null) {
+ node.get(ALLOW_READ).set(permission.getAllowRead().booleanValue());
+ }
+ if (permission.getAllowExecute() != null) {
+ node.get(ALLOW_EXECUTE).set(permission.getAllowExecute().booleanValue());
+ }
+ if(permission.getAllowAlter() != null) {
+ node.get(ALLOW_ALTER).set(permission.getAllowAlter().booleanValue());
+ }
+ return node;
+ }
+
+ public PermissionMetaData unwrap(ModelNode node) {
+ if (node == null) {
+ return null;
+ }
+
+ PermissionMetaData permission = new PermissionMetaData();
+ if (node.get(RESOURCE_NAME) != null) {
+ permission.setResourceName(node.get(RESOURCE_NAME).asString());
+ }
+ if (node.has(ALLOW_CREATE)) {
+ permission.setAllowCreate(node.get(ALLOW_CREATE).asBoolean());
+ }
+ if (node.has(ALLOW_DELETE)) {
+ permission.setAllowDelete(node.get(ALLOW_DELETE).asBoolean());
+ }
+ if (node.has(ALLOW_UPADTE)) {
+ permission.setAllowUpdate(node.get(ALLOW_UPADTE).asBoolean());
+ }
+ if (node.has(ALLOW_READ)) {
+ permission.setAllowRead(node.get(ALLOW_READ).asBoolean());
+ }
+ if (node.has(ALLOW_EXECUTE)) {
+ permission.setAllowExecute(node.get(ALLOW_EXECUTE).asBoolean());
+ }
+ if (node.has(ALLOW_ALTER)) {
+ permission.setAllowAlter(node.get(ALLOW_ALTER).asBoolean());
+ }
+ return permission;
+ }
+ public ModelNode describe(ModelNode node) {
+ addAttribute(node, RESOURCE_NAME, ModelType.STRING, true);
+ addAttribute(node, ALLOW_CREATE, ModelType.BOOLEAN, false);
+ addAttribute(node, ALLOW_DELETE, ModelType.BOOLEAN, false);
+ addAttribute(node, ALLOW_UPADTE, ModelType.BOOLEAN, false);
+ addAttribute(node, ALLOW_READ, ModelType.BOOLEAN, false);
+ addAttribute(node, ALLOW_EXECUTE, ModelType.BOOLEAN, false);
+ addAttribute(node, ALLOW_ALTER, ModelType.BOOLEAN, false);
+ return node;
+ }
+ }
+
+ public static class CacheStatisticsMetadataMapper implements MetadataMapper<CacheStatisticsMetadata>{
+ private static final String HITRATIO = "hit-ratio"; //$NON-NLS-1$
+ private static final String TOTAL_ENTRIES = "total-entries"; //$NON-NLS-1$
+ private static final String REQUEST_COUNT = "request-count"; //$NON-NLS-1$
+
+ public static CacheStatisticsMetadataMapper INSTANCE = new CacheStatisticsMetadataMapper();
+
+ public ModelNode wrap(CacheStatisticsMetadata object, ModelNode node) {
+ if (object == null)
+ return null;
+
+ node.get(ModelNodeConstants.TYPE).set(ModelType.OBJECT);
+
+ node.get(TOTAL_ENTRIES).set(object.getTotalEntries());
+ node.get(HITRATIO).set(object.getHitRatio());
+ node.get(REQUEST_COUNT).set(object.getRequestCount());
+
+ return node;
+ }
+
+ public CacheStatisticsMetadata unwrap(ModelNode node) {
+ if (node == null)
+ return null;
+
+ CacheStatisticsMetadata cache = new CacheStatisticsMetadata();
+ cache.setTotalEntries(node.get(TOTAL_ENTRIES).asInt());
+ cache.setHitRatio(node.get(HITRATIO).asDouble());
+ cache.setRequestCount(node.get(REQUEST_COUNT).asInt());
+ return cache;
+ }
+
+ public ModelNode describe(ModelNode node) {
+ node.get(TYPE).set(ModelType.OBJECT);
+ addAttribute(node, TOTAL_ENTRIES, ModelType.STRING, true);
+ addAttribute(node, HITRATIO, ModelType.STRING, true);
+ addAttribute(node, REQUEST_COUNT, ModelType.STRING, true);
+ return node;
+ }
+ }
+
+ public static class RequestMetadataMapper implements MetadataMapper<RequestMetadata>{
+ private static final String TRANSACTION_ID = "transaction-id"; //$NON-NLS-1$
+ private static final String NODE_ID = "node-id"; //$NON-NLS-1$
+ private static final String SOURCE_REQUEST = "source-request"; //$NON-NLS-1$
+ private static final String COMMAND = "command"; //$NON-NLS-1$
+ private static final String START_TIME = "start-time"; //$NON-NLS-1$
+ private static final String SESSION_ID = "session-id"; //$NON-NLS-1$
+ private static final String EXECUTION_ID = "execution-id"; //$NON-NLS-1$
+ private static final String STATE = "processing-state"; //$NON-NLS-1$
+ private static final String THREAD_STATE = "thread-state"; //$NON-NLS-1$
+
+ public static RequestMetadataMapper INSTANCE = new RequestMetadataMapper();
+
+ public ModelNode wrap(RequestMetadata request, ModelNode node) {
+ if (request == null) {
+ return null;
+ }
+ node.get(ModelNodeConstants.TYPE).set(ModelType.OBJECT);
+
+ node.get(EXECUTION_ID).set(request.getExecutionId());
+ node.get(SESSION_ID).set(request.getSessionId());
+ node.get(START_TIME).set(request.getStartTime());
+ node.get(COMMAND).set(request.getCommand());
+ node.get(SOURCE_REQUEST).set(request.sourceRequest());
+ if (request.getNodeId() != null) {
+ node.get(NODE_ID).set(request.getNodeId());
+ }
+ if (request.getTransactionId() != null) {
+ node.get(TRANSACTION_ID).set(request.getTransactionId());
+ }
+ node.get(STATE).set(request.getState().name());
+ node.get(THREAD_STATE).set(request.getThreadState().name());
+ return node;
+ }
+
+ public RequestMetadata unwrap(ModelNode node) {
+ if (node == null)
+ return null;
+
+ RequestMetadata request = new RequestMetadata();
+ request.setExecutionId(node.get(EXECUTION_ID).asLong());
+ request.setSessionId(node.get(SESSION_ID).asString());
+ request.setStartTime(node.get(START_TIME).asLong());
+ request.setCommand(node.get(COMMAND).asString());
+ request.setSourceRequest(node.get(SOURCE_REQUEST).asBoolean());
+ if (node.has(NODE_ID)) {
+ request.setNodeId(node.get(NODE_ID).asInt());
+ }
+ if (node.has(TRANSACTION_ID)) {
+ request.setTransactionId(node.get(TRANSACTION_ID).asString());
+ }
+ request.setState(ProcessingState.valueOf(node.get(STATE).asString()));
+ request.setThreadState(ThreadState.valueOf(node.get(THREAD_STATE).asString()));
+ return request;
+ }
+
+ public ModelNode describe(ModelNode node) {
+ node.get(TYPE).set(ModelType.OBJECT);
+ addAttribute(node, EXECUTION_ID, ModelType.LONG, true);
+ addAttribute(node, SESSION_ID, ModelType.STRING, true);
+ addAttribute(node, START_TIME, ModelType.LONG, true);
+ addAttribute(node, COMMAND, ModelType.STRING, true);
+ addAttribute(node, SOURCE_REQUEST, ModelType.BOOLEAN, true);
+ addAttribute(node, NODE_ID, ModelType.INT, false);
+ addAttribute(node, TRANSACTION_ID, ModelType.STRING, false);
+ addAttribute(node, STATE, ModelType.STRING, true);
+ addAttribute(node, THREAD_STATE, ModelType.STRING, true);
+ return node;
+ }
+ }
+
+ public static class SessionMetadataMapper implements MetadataMapper<SessionMetadata>{
+ private static final String SECURITY_DOMAIN = "security-domain"; //$NON-NLS-1$
+ private static final String VDB_VERSION = "vdb-version"; //$NON-NLS-1$
+ private static final String VDB_NAME = "vdb-name"; //$NON-NLS-1$
+ private static final String USER_NAME = "user-name"; //$NON-NLS-1$
+ private static final String SESSION_ID = "session-id"; //$NON-NLS-1$
+ private static final String LAST_PING_TIME = "last-ping-time"; //$NON-NLS-1$
+ private static final String IP_ADDRESS = "ip-address"; //$NON-NLS-1$
+ private static final String CLIENT_HOST_NAME = "client-host-address"; //$NON-NLS-1$
+ private static final String CREATED_TIME = "created-time"; //$NON-NLS-1$
+ private static final String APPLICATION_NAME = "application-name"; //$NON-NLS-1$
+ private static final String CLIENT_HARDWARE_ADRESS = "client-hardware-address"; //$NON-NLS-1$
+
+ public static SessionMetadataMapper INSTANCE = new SessionMetadataMapper();
+
+ public ModelNode wrap(SessionMetadata session, ModelNode node) {
+ if (session == null) {
+ return null;
+ }
+ node.get(ModelNodeConstants.TYPE).set(ModelType.OBJECT);
+
+ if (session.getApplicationName() != null) {
+ node.get(APPLICATION_NAME).set(session.getApplicationName());
+ }
+ node.get(CREATED_TIME).set(session.getCreatedTime());
+ node.get(CLIENT_HOST_NAME).set(session.getClientHostName());
+ node.get(IP_ADDRESS).set(session.getIPAddress());
+ node.get(LAST_PING_TIME).set(session.getLastPingTime());
+ node.get(SESSION_ID).set(session.getSessionId());
+ node.get(USER_NAME).set(session.getUserName());
+ node.get(VDB_NAME).set(session.getVDBName());
+ node.get(VDB_VERSION).set(session.getVDBVersion());
+ if (session.getSecurityDomain() != null){
+ node.get(SECURITY_DOMAIN).set(session.getSecurityDomain());
+ }
+ if (session.getClientHardwareAddress() != null) {
+ node.get(CLIENT_HARDWARE_ADRESS).set(session.getClientHardwareAddress());
+ }
+ return node;
+ }
+
+ public SessionMetadata unwrap(ModelNode node) {
+ if (node == null)
+ return null;
+
+ SessionMetadata session = new SessionMetadata();
+ if (node.has(APPLICATION_NAME)) {
+ session.setApplicationName(node.get(APPLICATION_NAME).asString());
+ }
+ session.setCreatedTime(node.get(CREATED_TIME).asLong());
+ session.setClientHostName(node.get(CLIENT_HOST_NAME).asString());
+ session.setIPAddress(node.get(IP_ADDRESS).asString());
+ session.setLastPingTime(node.get(LAST_PING_TIME).asLong());
+ session.setSessionId(node.get(SESSION_ID).asString());
+ session.setUserName(node.get(USER_NAME).asString());
+ session.setVDBName(node.get(VDB_NAME).asString());
+ session.setVDBVersion(node.get(VDB_VERSION).asInt());
+ if (node.has(SECURITY_DOMAIN)) {
+ session.setSecurityDomain(node.get(SECURITY_DOMAIN).asString());
+ }
+ if (node.has(CLIENT_HARDWARE_ADRESS)) {
+ session.setClientHardwareAddress(node.get(CLIENT_HARDWARE_ADRESS).asString());
+ }
+ return session;
+ }
+
+ public ModelNode describe(ModelNode node) {
+ node.get(TYPE).set(ModelType.OBJECT);
+ addAttribute(node, APPLICATION_NAME, ModelType.STRING, false);
+ addAttribute(node, CREATED_TIME, ModelType.LONG, true);
+ addAttribute(node, CLIENT_HOST_NAME, ModelType.LONG, true);
+ addAttribute(node, IP_ADDRESS, ModelType.STRING, true);
+ addAttribute(node, LAST_PING_TIME, ModelType.LONG, true);
+ addAttribute(node, SESSION_ID, ModelType.STRING, true);
+ addAttribute(node, USER_NAME, ModelType.STRING, true);
+ addAttribute(node, VDB_NAME, ModelType.STRING, true);
+ addAttribute(node, VDB_VERSION, ModelType.INT, true);
+ addAttribute(node, SECURITY_DOMAIN, ModelType.STRING, false);
+ return node;
+ }
+ }
+
+ public static class TransactionMetadataMapper implements MetadataMapper<TransactionMetadata>{
+ private static final String ID = "txn-id"; //$NON-NLS-1$
+ private static final String SCOPE = "txn-scope"; //$NON-NLS-1$
+ private static final String CREATED_TIME = "txn-created-time"; //$NON-NLS-1$
+ private static final String ASSOCIATED_SESSION = "session-id"; //$NON-NLS-1$
+
+ public static TransactionMetadataMapper INSTANCE = new TransactionMetadataMapper();
+
+ public ModelNode wrap(TransactionMetadata object, ModelNode transaction) {
+ if (object == null)
+ return null;
+
+ transaction.get(ModelNodeConstants.TYPE).set(ModelType.OBJECT);
+ transaction.get(ASSOCIATED_SESSION).set(object.getAssociatedSession());
+ transaction.get(CREATED_TIME).set(object.getCreatedTime());
+ transaction.get(SCOPE).set(object.getScope());
+ transaction.get(ID).set(object.getId());
+
+ return transaction;
+ }
+
+ public TransactionMetadata unwrap(ModelNode node) {
+ if (node == null)
+ return null;
+
+ TransactionMetadata transaction = new TransactionMetadata();
+ transaction.setAssociatedSession(node.get(ASSOCIATED_SESSION).asString());
+ transaction.setCreatedTime(node.get(CREATED_TIME).asLong());
+ transaction.setScope(node.get(SCOPE).asString());
+ transaction.setId(node.get(ID).asString());
+ return transaction;
+ }
+
+ public ModelNode describe(ModelNode node) {
+ node.get(TYPE).set(ModelType.OBJECT);
+ addAttribute(node, ASSOCIATED_SESSION, ModelType.STRING, true);
+ addAttribute(node, CREATED_TIME, ModelType.LONG, true);
+ addAttribute(node, SCOPE, ModelType.LONG, true);
+ addAttribute(node, ID, ModelType.STRING, true);
+ return node;
+ }
+ }
+
+ public static class WorkerPoolStatisticsMetadataMapper implements MetadataMapper<WorkerPoolStatisticsMetadata>{
+ private static final String MAX_THREADS = "max-threads"; //$NON-NLS-1$
+ private static final String HIGHEST_QUEUED = "highest-queued"; //$NON-NLS-1$
+ private static final String QUEUED = "queued"; //$NON-NLS-1$
+ private static final String QUEUE_NAME = "queue-name"; //$NON-NLS-1$
+ private static final String TOTAL_SUBMITTED = "total-submitted"; //$NON-NLS-1$
+ private static final String TOTAL_COMPLETED = "total-completed"; //$NON-NLS-1$
+ private static final String HIGHEST_ACTIVE_THREADS = "highest-active-threads"; //$NON-NLS-1$
+ private static final String ACTIVE_THREADS = "active-threads"; //$NON-NLS-1$
+
+ public static WorkerPoolStatisticsMetadataMapper INSTANCE = new WorkerPoolStatisticsMetadataMapper();
+
+ public ModelNode wrap(WorkerPoolStatisticsMetadata stats, ModelNode node) {
+ if (stats == null)
+ return null;
+ node.get(ModelNodeConstants.TYPE).set(ModelType.OBJECT);
+
+ node.get(ACTIVE_THREADS).set(stats.getActiveThreads());
+ node.get(HIGHEST_ACTIVE_THREADS).set(stats.getHighestActiveThreads());
+ node.get(TOTAL_COMPLETED).set(stats.getTotalCompleted());
+ node.get(TOTAL_SUBMITTED).set(stats.getTotalSubmitted());
+ node.get(QUEUE_NAME).set(stats.getQueueName());
+ node.get(QUEUED).set(stats.getQueued());
+ node.get(HIGHEST_QUEUED).set(stats.getHighestQueued());
+ node.get(MAX_THREADS).set(stats.getMaxThreads());
+
+ return node;
+ }
+
+ public WorkerPoolStatisticsMetadata unwrap(ModelNode node) {
+ if (node == null)
+ return null;
+
+ WorkerPoolStatisticsMetadata stats = new WorkerPoolStatisticsMetadata();
+ stats.setActiveThreads(node.get(ACTIVE_THREADS).asInt());
+ stats.setHighestActiveThreads(node.get(HIGHEST_ACTIVE_THREADS).asInt());
+ stats.setTotalCompleted(node.get(TOTAL_COMPLETED).asLong());
+ stats.setTotalSubmitted(node.get(TOTAL_SUBMITTED).asLong());
+ stats.setQueueName(node.get(QUEUE_NAME).asString());
+ stats.setQueued(node.get(QUEUED).asInt());
+ stats.setHighestQueued(node.get(HIGHEST_QUEUED).asInt());
+ stats.setMaxThreads(node.get(MAX_THREADS).asInt());
+ return stats;
+ }
+
+ public ModelNode describe(ModelNode node) {
+ node.get(TYPE).set(ModelType.OBJECT);
+ addAttribute(node, ACTIVE_THREADS, ModelType.INT, true);
+ addAttribute(node, HIGHEST_ACTIVE_THREADS, ModelType.INT, true);
+ addAttribute(node, TOTAL_COMPLETED, ModelType.LONG, true);
+ addAttribute(node, TOTAL_SUBMITTED, ModelType.LONG, true);
+ addAttribute(node, QUEUE_NAME, ModelType.STRING, true);
+ addAttribute(node, QUEUED, ModelType.INT, true);
+ addAttribute(node, HIGHEST_QUEUED, ModelType.INT, true);
+ addAttribute(node, MAX_THREADS, ModelType.INT, true);
+ return node;
+ }
+ }
+
+ private static final String CHILDREN = "children"; //$NON-NLS-1$
+ private static final String ATTRIBUTES = "attributes"; //$NON-NLS-1$
+ private static final String DOT_DESC = ".describe"; //$NON-NLS-1$
+ private static final String TYPE = "type"; //$NON-NLS-1$
+ private static final String MIN_OCCURS = "min-occurs"; //$NON-NLS-1$
+ private static final String REQUIRED = "required"; //$NON-NLS-1$
+ private static final String ALLOWED = "allowed"; //$NON-NLS-1$
+ static ModelNode addAttribute(ModelNode node, String name, ModelType dataType, boolean required) {
+ node.get(ATTRIBUTES, name, TYPE).set(dataType);
+ node.get(ATTRIBUTES, name, DESCRIPTION).set(AdminPlugin.Util.getString(name+DOT_DESC));
+ node.get(ATTRIBUTES, name, REQUIRED).set(required);
+ return node;
+ }
+}
+
+
Property changes on: branches/as7/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataMapper.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: branches/as7/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java
===================================================================
--- branches/as7/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -22,19 +22,16 @@
package org.teiid.adminapi.impl;
import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
+import java.io.OutputStream;
+import java.util.*;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.*;
+import org.teiid.adminapi.DataPolicy;
import org.teiid.adminapi.Model;
+import org.teiid.adminapi.Translator;
import org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData;
import org.teiid.adminapi.impl.ModelMetaData.ValidationError;
-import org.teiid.adminapi.impl.VDBMetaData;
@SuppressWarnings("nls")
public class VDBMetadataParser {
@@ -306,5 +303,153 @@
final Element element = elements.get(localName);
return element == null ? UNKNOWN : element;
}
- }
+ }
+
+ public static void marshell(VDBMetaData vdb, OutputStream out) throws XMLStreamException {
+ XMLStreamWriter writer = XMLOutputFactory.newFactory().createXMLStreamWriter(out);
+
+ writer.writeStartElement(Element.VDB.getLocalName());
+ writer.writeAttribute(Element.NAME.getLocalName(), vdb.getName());
+ writer.writeAttribute(Element.VERSION.getLocalName(), String.valueOf(vdb.getVersion()));
+
+ if (vdb.getDescription() != null) {
+ writeElement(writer, Element.DESCRIPTION, vdb.getDescription());
+ }
+ writeProperties(writer, vdb.getProperties());
+
+ // models
+ Collection<ModelMetaData> models = vdb.getModelMetaDatas().values();
+ for (ModelMetaData model:models) {
+ writeModel(writer, model);
+ }
+
+ // override translators
+ for(Translator translator:vdb.getOverrideTranslators()) {
+ writeTranslator(writer, translator);
+ }
+
+ // data-roles
+ for (DataPolicy dp:vdb.getDataPolicies()) {
+ writeDataPolicy(writer, dp);
+ }
+
+ // entry
+ // designer only
+
+ writer.writeEndElement();
+ }
+
+ private static void writeDataPolicy(XMLStreamWriter writer, DataPolicy dp) throws XMLStreamException {
+ writer.writeStartElement(Element.DATA_ROLE.getLocalName());
+
+ writer.writeAttribute(Element.NAME.getLocalName(), dp.getName());
+ writer.writeAttribute(Element.DATA_ROLE_ANY_ATHENTICATED_ATTR.getLocalName(), String.valueOf(dp.isAnyAuthenticated()));
+ writer.writeAttribute(Element.DATA_ROLE_ALLOW_TEMP_TABLES_ATTR.getLocalName(), String.valueOf(dp.isAllowCreateTemporaryTables()));
+
+ writeElement(writer, Element.DESCRIPTION, dp.getDescription());
+
+ // permission
+ for (DataPolicy.DataPermission permission: dp.getPermissions()) {
+ writer.writeStartElement(Element.PERMISSION.getLocalName());
+ writeElement(writer, Element.RESOURCE_NAME, permission.getResourceName());
+ if (permission.getAllowCreate() != null) {
+ writeElement(writer, Element.ALLOW_CREATE, permission.getAllowCreate().toString());
+ }
+ if (permission.getAllowRead() != null) {
+ writeElement(writer, Element.ALLOW_READ, permission.getAllowRead().toString());
+ }
+ if (permission.getAllowUpdate() != null) {
+ writeElement(writer, Element.ALLOW_UPADTE, permission.getAllowUpdate().toString());
+ }
+ if (permission.getAllowDelete() != null) {
+ writeElement(writer, Element.ALLOW_DELETE, permission.getAllowDelete().toString());
+ }
+ if (permission.getAllowExecute() != null) {
+ writeElement(writer, Element.ALLOW_EXECUTE, permission.getAllowExecute().toString());
+ }
+ if (permission.getAllowAlter() != null) {
+ writeElement(writer, Element.ALLOW_ALTER, permission.getAllowAlter().toString());
+ }
+ writer.writeEndElement();
+ }
+
+ // mapped role names
+ for (String roleName:dp.getMappedRoleNames()) {
+ writeElement(writer, Element.MAPPED_ROLE_NAME, roleName);
+ }
+
+ writer.writeEndElement();
+ }
+
+ private static void writeTranslator(final XMLStreamWriter writer, Translator translator) throws XMLStreamException {
+ writer.writeStartElement(Element.TRANSLATOR.getLocalName());
+
+ writer.writeAttribute(Element.NAME.getLocalName(), translator.getName());
+ writer.writeAttribute(Element.TYPE.getLocalName(), translator.getType());
+ writer.writeAttribute(Element.DESCRIPTION.getLocalName(), translator.getDescription());
+
+ writeProperties(writer, translator.getProperties());
+
+ writer.writeEndElement();
+ }
+
+ private static void writeModel(final XMLStreamWriter writer, ModelMetaData model) throws XMLStreamException {
+ writer.writeStartElement(Element.MODEL.getLocalName());
+ writer.writeAttribute(Element.NAME.getLocalName(), model.getName());
+ writer.writeAttribute(Element.TYPE.getLocalName(), model.getModelType().name());
+
+ writer.writeAttribute(Element.VISIBLE.getLocalName(), String.valueOf(model.isVisible()));
+ if (model.getPath() != null) {
+ writer.writeAttribute(Element.PATH.getLocalName(), model.getPath());
+ }
+
+ if (model.getDescription() != null) {
+ writeElement(writer, Element.DESCRIPTION, model.getDescription());
+ }
+ writeProperties(writer, model.getProperties());
+
+ // source mappings
+ for (SourceMappingMetadata source:model.getSourceMappings()) {
+ writer.writeStartElement(Element.SOURCE.getLocalName());
+ writer.writeAttribute(Element.NAME.getLocalName(), source.getName());
+ writer.writeAttribute(Element.SOURCE_TRANSLATOR_NAME_ATTR.getLocalName(), source.getTranslatorName());
+ writer.writeAttribute(Element.SOURCE_CONNECTION_JNDI_NAME_ATTR.getLocalName(), source.getConnectionJndiName());
+ writer.writeEndElement();
+ }
+
+ // model validation errors
+ for (ValidationError ve:model.getErrors()) {
+ writer.writeStartElement(Element.VALIDATION_ERROR.getLocalName());
+ writer.writeAttribute(Element.VALIDATION_SEVERITY_ATTR.getLocalName(), ve.getSeverity());
+ if (ve.getPath() != null) {
+ writer.writeAttribute(Element.PATH.getLocalName(), ve.getPath());
+ }
+ writer.writeCharacters(ve.getValue());
+ writer.writeEndElement();
+ }
+ writer.writeEndElement();
+ }
+
+ private static void writeProperties(final XMLStreamWriter writer, Properties props) throws XMLStreamException {
+ Enumeration keys = props.propertyNames();
+ while (keys.hasMoreElements()) {
+ writer.writeStartElement(Element.PROPERTY.getLocalName());
+ String key = (String)keys.nextElement();
+ String value = props.getProperty(key);
+ writer.writeAttribute(Element.NAME.getLocalName(), key);
+ writer.writeAttribute(Element.VALUE.getLocalName(), value);
+ writer.writeEndElement();
+ }
+ }
+
+ private static void writeElement(final XMLStreamWriter writer, final Element element, String value) throws XMLStreamException {
+ writer.writeStartElement(element.getLocalName());
+ writer.writeCharacters(value);
+ writer.writeEndElement();
+ }
+
+ private static void writeAttribute(final XMLStreamWriter writer, final Element element, final String value) throws XMLStreamException {
+ writer.writeAttribute(element.getLocalName(),value);
+ }
+
}
Copied: branches/as7/admin/src/main/resources/org/teiid/adminapi/i18n.properties (from rev 3450, branches/as7/client/src/main/resources/org/teiid/adminapi/i18n.properties)
===================================================================
--- branches/as7/admin/src/main/resources/org/teiid/adminapi/i18n.properties (rev 0)
+++ branches/as7/admin/src/main/resources/org/teiid/adminapi/i18n.properties 2011-09-23 04:11:11 UTC (rev 3503)
@@ -0,0 +1,72 @@
+description.describe=Description
+vdb-name.describe=The Virtual Database Name
+model-name.describe=Name of the model
+model-path.describe=Path to model file inside the archive
+translator-name.describe=Name of the Translator
+connection-type.describe=Allowable Connections: 1) NONE - disallow new connections 2) BY VERSION - allow connections only if the version is specified or if this is the earliest 'BY VERSION' vdb and there are no vdbs marked as 'ANY' 3) ANY - allow connections with or without a version specified. If multiple versions of same VDB are deployed, connect to one specified with ANY, or if there are multiple VDBs with ANY then connect to the latest version with ANY
+status.describe=The Virtual Database Status
+vdb-version.describe=The Virtual Database Version
+url.describe=The Virtual Database URL
+dynamic.describe=Dynamic Virtual Database
+property-name.describe=Name
+property-value.describe=Property value
+visible.describe=Visibility of the model
+model-type.describe=Type of the Model(PHYSICAL, VIRTUAL, FUNCTION, OTHER)
+source-name.describe=Source name for this model
+jndi-name.describe=Connection JNDI Name
+translator-name.describe=Name of the translator
+error-path.describe=Path to the error in the Virtual Database
+severity.describe=Severity
+message.describe=Error message
+base-type.describe=Translator Base Type
+module-name.describe=Translator's Module name
+allow-create-temp-tables.describe=Allows create of temporary table
+any-authenticated.describe=Indicates if the role is mapped to any authenticated user
+policy-name.describe=Resource Name, for which permission defined
+properties.describe=properties
+source-mappings.describe=Model to source mapping
+validity-errors.describe=Model validation errors
+models.describe=Models inside a virtual database
+override-translators.describe=Overridden translators for the Virtual Database
+data-policies.describe=Data access policies defined for the Virtual Database
+data-permissions.describe=Permissions defined for data access
+mapped-role-names.describe=Policy name to role name mapping
+
+execution-id.describe=Unique Identifier for Request
+session-id.describe=Session Identifier
+start-time.describe=Start time for the request
+command.describe=Executing Command
+source-request.describe=Is this Connector level request
+node-id.describe=Node Identifier
+transaction-id.describe=Get Transaction XID if transaction involved
+processing-state.describe=State of the Request
+thread-state.describe=Thread state
+
+application-name.describe=Application assosiated with Session
+created-time.describe=When session created
+client-host-address.describe=Host name from where the session created
+ip-address.describe=IP address from where session is created
+last-ping-time.describe=Last ping time
+user-name.describe=User name associated with session
+security-domain.describe=Security domain that session used for login
+
+
+txn-created-time.describe=Transaction created time
+txn-scope.describe=Transaction scope (Request, Local, Global)
+txn-id.describe=Transaction Identifier (XID)
+
+max-threads.describe=Max Threads
+highest-queued.describe=Highest Queued Tasks
+queued.describe=Currently Queued Tasks
+queue-name.describe=Queue Name
+total-submitted.describe=Total submitted Tasks
+total-completed.describe=Total Completed Tasks
+highest-active-threads.describe=Highest active threads
+active-threads.describe=Number of Active Threads
+
+allow-create.describe=create allowed
+allow-read.describe= read allowed
+allow-update.describe = update allowed
+allow-delete.describe = delete allowed
+allow-execute.describe = execute allowed
+allow-alter.describe = alter allowed
\ No newline at end of file
Property changes on: branches/as7/admin/src/main/resources/org/teiid/adminapi/i18n.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: branches/as7/admin/src/test/java/org/teiid/adminapi/impl/TestRequestMetadata.java
===================================================================
--- branches/as7/admin/src/test/java/org/teiid/adminapi/impl/TestRequestMetadata.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/admin/src/test/java/org/teiid/adminapi/impl/TestRequestMetadata.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -34,9 +34,9 @@
@Test public void testMapping() {
RequestMetadata request = buildRequest();
- ModelNode node = MetadataMapper.RequestMetadataMapper.wrap(request, new ModelNode());
+ ModelNode node = VDBMetadataMapper.RequestMetadataMapper.INSTANCE.wrap(request, new ModelNode());
- RequestMetadata actual = MetadataMapper.RequestMetadataMapper.unwrap(node);
+ RequestMetadata actual = VDBMetadataMapper.RequestMetadataMapper.INSTANCE.unwrap(node);
assertEquals(request, actual);
assertEquals(request.getState(), actual.getState());
@@ -128,7 +128,7 @@
" }\n" +
"}";
@Test public void testDescribe() {
- assertEquals(desc, MetadataMapper.RequestMetadataMapper.describe(new ModelNode()).toJSONString(false));
+ assertEquals(desc, VDBMetadataMapper.RequestMetadataMapper.INSTANCE.describe(new ModelNode()).toJSONString(false));
}
}
Modified: branches/as7/admin/src/test/java/org/teiid/adminapi/impl/TestSessionMetadata.java
===================================================================
--- branches/as7/admin/src/test/java/org/teiid/adminapi/impl/TestSessionMetadata.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/admin/src/test/java/org/teiid/adminapi/impl/TestSessionMetadata.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -42,9 +42,9 @@
session.setSecurityContext("auth-domain");
session.setUserName("user");
- ModelNode node = MetadataMapper.SessionMetadataMapper.wrap(session, new ModelNode());
+ ModelNode node = VDBMetadataMapper.SessionMetadataMapper.INSTANCE.wrap(session, new ModelNode());
- SessionMetadata session1 = MetadataMapper.SessionMetadataMapper.unwrap(node);
+ SessionMetadata session1 = VDBMetadataMapper.SessionMetadataMapper.INSTANCE.unwrap(node);
assertEquals(session.getSessionId(), session1.getSessionId());
assertEquals(session.getApplicationName(), session1.getApplicationName());
@@ -130,7 +130,7 @@
"}";
@Test public void testDescribe() {
- ModelNode n = MetadataMapper.SessionMetadataMapper.describe(new ModelNode());
+ ModelNode n = VDBMetadataMapper.SessionMetadataMapper.INSTANCE.describe(new ModelNode());
//System.out.println(n.toJSONString(false));
assertEquals(describe, n.toJSONString(false));
}
Modified: branches/as7/admin/src/test/java/org/teiid/adminapi/impl/TestTransactionMetadata.java
===================================================================
--- branches/as7/admin/src/test/java/org/teiid/adminapi/impl/TestTransactionMetadata.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/admin/src/test/java/org/teiid/adminapi/impl/TestTransactionMetadata.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -37,9 +37,9 @@
tm.setId("tnx-id");
tm.setScope("scope");
- ModelNode node = MetadataMapper.TransactionMetadataMapper.wrap(tm, new ModelNode());
+ ModelNode node = VDBMetadataMapper.TransactionMetadataMapper.INSTANCE.wrap(tm, new ModelNode());
- TransactionMetadata tm1 = MetadataMapper.TransactionMetadataMapper.unwrap(node);
+ TransactionMetadata tm1 = VDBMetadataMapper.TransactionMetadataMapper.INSTANCE.unwrap(node);
assertEquals(tm.getAssociatedSession(), tm1.getAssociatedSession());
@@ -85,7 +85,7 @@
"}";
@Test
public void testDescribe() {
- ModelNode n = MetadataMapper.TransactionMetadataMapper.describe(new ModelNode());
+ ModelNode n = VDBMetadataMapper.TransactionMetadataMapper.INSTANCE.describe(new ModelNode());
//System.out.println(n.toJSONString(false));
assertEquals(describe, n.toJSONString(false));
}
Modified: branches/as7/admin/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java
===================================================================
--- branches/as7/admin/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/admin/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -51,7 +51,7 @@
public class TestVDBMetaData {
@Test
- public void testMarshellUnmarshell() throws Exception {
+ public void testMarshellUnmarshellUsingJaxb() throws Exception {
VDBMetaData vdb = buildVDB();
@@ -65,7 +65,7 @@
StringWriter sw = new StringWriter();
marshell.marshal(vdb, sw);
- System.out.println(sw.toString());
+ //System.out.println(sw.toString());
// UnMarshell
Unmarshaller un = jc.createUnmarshaller();
@@ -74,7 +74,24 @@
validateVDB(vdb);
}
+
+
+ @Test
+ public void testMarshellUnmarshellDirectParsing() throws Exception {
+
+ VDBMetaData vdb = buildVDB();
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ VDBMetadataParser.marshell(vdb, out);
+
+ //System.out.println(new String(out.toByteArray()));
+ // UnMarshell
+ vdb = VDBMetadataParser.unmarshell(new ByteArrayInputStream(out.toByteArray()));
+
+ validateVDB(vdb);
+ }
+
static void validateVDB(VDBMetaData vdb) {
ModelMetaData modelOne;
ModelMetaData modelTwo;
@@ -217,16 +234,17 @@
@Test public void testVDBMetaDataMapper() {
VDBMetaData vdb = buildVDB();
- ModelNode node = MetadataMapper.wrap(vdb, new ModelNode());
+ ModelNode node = VDBMetadataMapper.INSTANCE.wrap(vdb, new ModelNode());
- vdb = MetadataMapper.unwrap(node);
+ vdb = VDBMetadataMapper.INSTANCE.unwrap(node);
validateVDB(vdb);
}
@Test
public void testVDBMetaDataDescribe() throws Exception {
- ModelNode node = MetadataMapper.describe(new ModelNode());
+ ModelNode node = VDBMetadataMapper.INSTANCE.describe(new ModelNode());
String actual = node.toJSONString(false);
+
assertEquals(ObjectConverterUtil.convertFileToString(new File(UnitTestUtil.getTestDataPath() + "/vdb-describe.txt")), actual);
}
}
Added: branches/as7/admin/src/test/resources/vdb-describe.txt
===================================================================
--- branches/as7/admin/src/test/resources/vdb-describe.txt (rev 0)
+++ branches/as7/admin/src/test/resources/vdb-describe.txt 2011-09-23 04:11:11 UTC (rev 3503)
@@ -0,0 +1,333 @@
+{
+ "type" : {
+ "TYPE_MODEL_VALUE" : "OBJECT"
+ },
+ "attributes" : {
+ "vdb-name" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "The Virtual Database Name",
+ "required" : true
+ },
+ "connection-type" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Allowable Connections: 1) NONE - disallow new connections 2) BY VERSION - allow connections only if the version is specified or if this is the earliest 'BY VERSION' vdb and there are no vdbs marked as 'ANY' 3) ANY - allow connections with or without a version specified. If multiple versions of same VDB are deployed, connect to one specified with ANY, or if there are multiple VDBs with ANY then connect to the latest version with ANY ",
+ "required" : false
+ },
+ "status" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "The Virtual Database Status",
+ "required" : true
+ },
+ "vdb-version" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "INT"
+ },
+ "description" : "The Virtual Database Version",
+ "required" : true
+ },
+ "url" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "The Virtual Database URL",
+ "required" : false
+ },
+ "description" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Description",
+ "required" : false
+ },
+ "dynamic" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "BOOLEAN"
+ },
+ "description" : "Dynamic Virtual Database",
+ "required" : false
+ }
+ },
+ "allowed" : [
+ "ACTIVE",
+ "INACTIVE"
+ ],
+ "children" : {
+ "properties" : {
+ "description" : "properties",
+ "type" : {
+ "TYPE_MODEL_VALUE" : "OBJECT"
+ },
+ "attributes" : {
+ "property-name" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Name",
+ "required" : true
+ },
+ "property-value" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Property value",
+ "required" : true
+ }
+ }
+ },
+ "models" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "OBJECT"
+ },
+ "attributes" : {
+ "model-name" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Name of the model",
+ "required" : true
+ },
+ "description" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Description",
+ "required" : false
+ },
+ "visible" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "BOOLEAN"
+ },
+ "description" : "Visibility of the model",
+ "required" : false
+ },
+ "model-type" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Type of the Model(PHYSICAL, VIRTUAL, FUNCTION, OTHER)",
+ "required" : true
+ },
+ "model-path" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Path to model file inside the archive",
+ "required" : false
+ }
+ },
+ "allowed" : [
+ "PHYSICAL",
+ "VIRTUAL",
+ "FUNCTION",
+ "OTHER"
+ ],
+ "children" : {
+ "properties" : {
+ "description" : "properties",
+ "type" : {
+ "TYPE_MODEL_VALUE" : "OBJECT"
+ },
+ "attributes" : {
+ "property-name" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Name",
+ "required" : true
+ },
+ "property-value" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Property value",
+ "required" : true
+ }
+ }
+ },
+ "source-mappings" : {
+ "description" : "Model to source mapping",
+ "type" : {
+ "TYPE_MODEL_VALUE" : "OBJECT"
+ },
+ "attributes" : {
+ "source-name" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Source name for this model",
+ "required" : true
+ },
+ "jndi-name" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Connection JNDI Name",
+ "required" : true
+ },
+ "translator-name" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Name of the translator",
+ "required" : true
+ }
+ }
+ },
+ "validity-errors" : {
+ "description" : "Model validation errors",
+ "type" : {
+ "TYPE_MODEL_VALUE" : "OBJECT"
+ },
+ "attributes" : {
+ "error-path" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Path to the error in the Virtual Database",
+ "required" : false
+ },
+ "severity" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Severity",
+ "required" : true
+ },
+ "message" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Error message",
+ "required" : true
+ }
+ }
+ }
+ },
+ "description" : "Models inside a virtual database",
+ "min-occurs" : 1
+ },
+ "override-translators" : {
+ "description" : "Overridden translators for the Virtual Database",
+ "type" : {
+ "TYPE_MODEL_VALUE" : "OBJECT"
+ },
+ "attributes" : {
+ "translator-name" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Name of the translator",
+ "required" : true
+ },
+ "base-type" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Translator Base Type",
+ "required" : true
+ },
+ "description" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Description",
+ "required" : false
+ },
+ "module-name" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Translator's Module name",
+ "required" : false
+ }
+ },
+ "children" : {"properties" : {
+ "description" : "properties",
+ "type" : {
+ "TYPE_MODEL_VALUE" : "OBJECT"
+ },
+ "attributes" : {
+ "property-name" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Name",
+ "required" : true
+ },
+ "property-value" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Property value",
+ "required" : true
+ }
+ }
+ }}
+ },
+ "data-policies" : {
+ "description" : "Data access policies defined for the Virtual Database",
+ "type" : {
+ "TYPE_MODEL_VALUE" : "OBJECT"
+ },
+ "attributes" : {
+ "policy-name" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Resource Name, for which permission defined",
+ "required" : true
+ },
+ "description" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ },
+ "description" : "Description",
+ "required" : false
+ },
+ "allow-create-temp-tables" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "BOOLEAN"
+ },
+ "description" : "Allows create of temporary table",
+ "required" : false
+ },
+ "any-authenticated" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "BOOLEAN"
+ },
+ "description" : "Indicates if the role is mapped to any authenticated user",
+ "required" : false
+ }
+ },
+ "children" : {
+ "data-permissions" : {
+ "description" : "Permissions defined for data access",
+ "min-occurs" : 1,
+ "children" : {
+ "allow-create" : {"description" : "create allowed"},
+ "allow-read" : {"description" : "read allowed"},
+ "allow-update" : {"description" : "update allowed"},
+ "allow-delete" : {"description" : "delete allowed"},
+ "allow-execute" : {"description" : "execute allowed"},
+ "allow-alter" : {"description" : "alter allowed"}
+ }
+ },
+ "mapped-role-names" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "LIST"
+ },
+ "description" : "Policy name to role name mapping",
+ "value-type" : {
+ "TYPE_MODEL_VALUE" : "STRING"
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
Property changes on: branches/as7/admin/src/test/resources/vdb-describe.txt
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: branches/as7/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java
===================================================================
--- branches/as7/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -82,7 +82,7 @@
@SuppressWarnings("nls")
public static void connectAsAdmin() throws AdminException {
loadConnectionProperties();
- connectAsAdmin(p.getProperty("admin.host", "localhost"), Integer.parseInt(p.getProperty("admin.port", "9990")), p.getProperty("admin.user", "admin"), p.getProperty("admin.password", "admin"), "conn-" + connectionCount++);
+ connectAsAdmin(p.getProperty("admin.host", "localhost"), Integer.parseInt(p.getProperty("admin.port", "9999")), p.getProperty("admin.user", "admin"), p.getProperty("admin.password", "admin"), "conn-" + connectionCount++);
}
static void loadConnectionProperties() {
@@ -150,11 +150,9 @@
getAdmin().clearCache(cacheType, vdbName, vdbVersion);
}
- @Doc(text = "Delete a VDB")
- public static void deleteVDB(
- @Doc(text = "vdb name") String vdbName,
- @Doc(text = "vdb version") int vdbVersion) throws AdminException {
- getAdmin().deleteVDB(vdbName, vdbVersion);
+ @Doc(text = "Undeploy a artifact (JAR, RAR, VDB)")
+ public static void undeploy(@Doc(text = "deployed name") String deployedName) throws AdminException {
+ getAdmin().undeploy(deployedName);
}
@Doc(text = "Get all cache type Strings")
@@ -172,7 +170,7 @@
}
@Doc(text = "Get all translator instances")
- public static Collection<Translator> getTranslators()
+ public static Collection<? extends Translator> getTranslators()
throws AdminException {
return getAdmin().getTranslators();
}
@@ -185,30 +183,30 @@
}
@Doc(text = "Get all PropertyDefinitions for the given template")
- public static Collection<PropertyDefinition> getTemplatePropertyDefinitions(
+ public static Collection<? extends PropertyDefinition> getTemplatePropertyDefinitions(
@Doc(text = "template name") String templateName) throws AdminException {
return getAdmin().getTemplatePropertyDefinitions(templateName);
}
@Doc(text = "Get all Request instances")
- public static Collection<Request> getRequests() throws AdminException {
+ public static Collection<? extends Request> getRequests() throws AdminException {
return getAdmin().getRequests();
}
@Doc(text = "Get all Request instances for the given session")
- public static Collection<Request> getRequestsForSession(
+ public static Collection<? extends Request> getRequestsForSession(
@Doc(text = "session id") String sessionId)
throws AdminException {
return getAdmin().getRequestsForSession(sessionId);
}
@Doc(text = "Get all Session instances")
- public static Collection<Session> getSessions() throws AdminException {
+ public static Collection<? extends Session> getSessions() throws AdminException {
return getAdmin().getSessions();
}
@Doc(text = "Get all Transaction instances")
- public static Collection<Transaction> getTransactions() throws AdminException {
+ public static Collection<? extends Transaction> getTransactions() throws AdminException {
return getAdmin().getTransactions();
}
@@ -220,7 +218,7 @@
}
@Doc(text = "Get all VDB instances")
- public static Set<VDB> getVDBs() throws AdminException {
+ public static Set<? extends VDB> getVDBs() throws AdminException {
return getAdmin().getVDBs();
}
@@ -279,7 +277,7 @@
@Doc(text = "Checks if a translator exists")
public static boolean hasTranslator(@Doc(text = "deployed name") String factoryName) throws AdminException {
- Collection<Translator> bindings = getAdmin().getTranslators();
+ Collection<? extends Translator> bindings = getAdmin().getTranslators();
for (Translator binding:bindings) {
if (binding.getName().equals(factoryName)) {
@@ -292,7 +290,7 @@
@Doc(text = "Checks if a VDB exists")
public static boolean hasVDB(
@Doc(text = "vdb name") String vdbName) throws AdminException {
- Collection<VDB> vdbs = getAdmin().getVDBs();
+ Collection<? extends VDB> vdbs = getAdmin().getVDBs();
for (VDB vdb:vdbs) {
if (vdb.getName().equals(vdbName)) {
return true;
@@ -305,7 +303,7 @@
public static boolean hasVDB(
@Doc(text = "vdb name") String vdbName,
@Doc(text = "vdb version") int version) throws AdminException {
- Collection<VDB> vdbs = getAdmin().getVDBs();
+ Collection<? extends VDB> vdbs = getAdmin().getVDBs();
for (VDB vdb:vdbs) {
if (vdb.getName().equals(vdbName) && vdb.getVersion() == version) {
return true;
@@ -322,13 +320,12 @@
ObjectConverterUtil.write(contents, fileName);
}*/
- @Doc(text = "Deploy a VDB from file")
- public static void deployVDB(
- @Doc(text = "file name") String vdbFile) throws AdminException, FileNotFoundException {
+ @Doc(text = "Deploy a Artifact (JAR, RAR, VDB) from file")
+ public static void deploy(@Doc(text = "file name") String vdbFile) throws AdminException, FileNotFoundException {
File file = new File(vdbFile);
FileInputStream fis = new FileInputStream(file);
try {
- getAdmin().deployVDB(file.getName(), fis);
+ getAdmin().deploy(file.getName(), fis);
} finally {
try {
fis.close();
Modified: branches/as7/adminshell/src/test/java/org/teiid/adminshell/TestAdminShell.java
===================================================================
--- branches/as7/adminshell/src/test/java/org/teiid/adminshell/TestAdminShell.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/adminshell/src/test/java/org/teiid/adminshell/TestAdminShell.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -48,8 +48,8 @@
}
@Test public void testDeployVDB() throws AdminException, FileNotFoundException {
- AdminShell.deployVDB(UnitTestUtil.getTestDataPath() + "/foo/bar.txt");
- Mockito.verify(admin).deployVDB(Mockito.eq("bar.txt"), (InputStream)Mockito.anyObject());
+ AdminShell.deploy(UnitTestUtil.getTestDataPath() + "/foo/bar.txt");
+ Mockito.verify(admin).deploy(Mockito.eq("bar.txt"), (InputStream)Mockito.anyObject());
}
}
Modified: branches/as7/build/assembly/jboss-as7/dist.xml
===================================================================
--- branches/as7/build/assembly/jboss-as7/dist.xml 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/build/assembly/jboss-as7/dist.xml 2011-09-23 04:11:11 UTC (rev 3503)
@@ -1,4 +1,4 @@
-<!--This script builds a JAR for the Embedded Server Installation -->
+<!--This script builds a zip for Teiid Server Installation -->
<assembly>
<id>jboss-dist</id>
Modified: branches/as7/build/kits/adminshell/connection.properties
===================================================================
--- branches/as7/build/kits/adminshell/connection.properties 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/build/kits/adminshell/connection.properties 2011-09-23 04:11:11 UTC (rev 3503)
@@ -2,6 +2,7 @@
jdbc.password=user
jdbc.url=jdbc:teiid:admin@mm://localhost:31000;
-admin.url=mms://localhost:31443
+admin.host=localhost
+admin.port=9999
admin.user=admin
admin.password=admin
Deleted: branches/as7/client/src/main/resources/org/teiid/adminapi/i18n.properties
===================================================================
--- branches/as7/client/src/main/resources/org/teiid/adminapi/i18n.properties 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/client/src/main/resources/org/teiid/adminapi/i18n.properties 2011-09-23 04:11:11 UTC (rev 3503)
@@ -1,65 +0,0 @@
-description.describe=Description
-vdb-name.describe=The Virtual Database Name
-model-name.describe=Name of the model
-model-path.describe=Path to model file inside the archive
-translator-name.describe=Name of the Translator
-connection-type.describe=Allowable Connections: 1) NONE - disallow new connections 2) BY VERSION - allow connections only if the version is specified or if this is the earliest 'BY VERSION' vdb and there are no vdbs marked as 'ANY' 3) ANY - allow connections with or without a version specified. If multiple versions of same VDB are deployed, connect to one specified with ANY, or if there are multiple VDBs with ANY then connect to the latest version with ANY
-status.describe=The Virtual Database Status
-vdb-version.describe=The Virtual Database Version
-url.describe=The Virtual Database URL
-dynamic.describe=Dynamic Virtual Database
-property-name.describe=Name
-property-value.describe=Property value
-visible.describe=Visibility of the model
-model-type.describe=Type of the Model(PHYSICAL, VIRTUAL, FUNCTION, OTHER)
-source-name.describe=Source name for this model
-jndi-name.describe=Connection JNDI Name
-translator-name.describe=Name of the translator
-error-path.describe=Path to the error in the Virtual Database
-severity.describe=Severity
-message.describe=Error message
-base-type.describe=Translator Base Type
-module-name.describe=Translator's Module name
-allow-create-temp-tables.describe=Allows create of temporary table
-any-authenticated.describe=Indicates if the role is mapped to any authenticated user
-policy-name.describe=Resource Name, for which permission defined
-properties.describe=properties
-source-mappings.describe=Model to source mapping
-validity-errors.describe=Model validation errors
-models.describe=Models inside a virtual database
-override-translators.describe=Overridden translators for the Virtual Database
-data-policies.describe=Data access policies defined for the Virtual Database
-data-permissions.describe=Permissions defined for data access
-mapped-role-names.describe=Policy name to role name mapping
-
-execution-id.describe=Unique Identifier for Request
-session-id.describe=Session Identifier
-start-time.describe=Start time for the request
-command.describe=Executing Command
-source-request.describe=Is this Connector level request
-node-id.describe=Node Identifier
-transaction-id.describe=Get Transaction XID if transaction involved
-processing-state.describe=State of the Request
-thread-state.describe=Thread state
-
-application-name.describe=Application assosiated with Session
-created-time.describe=When session created
-client-host-address.describe=Host name from where the session created
-ip-address.describe=IP address from where session is created
-last-ping-time.describe=Last ping time
-user-name.describe=User name associated with session
-security-domain.describe=Security domain that session used for login
-
-
-txn-created-time.describe=Transaction created time
-txn-scope.describe=Transaction scope (Request, Local, Global)
-txn-id.describe=Transaction Identifier (XID)
-
-max-threads.describe=Max Threads
-highest-queued.describe=Highest Queued Tasks
-queued.describe=Currently Queued Tasks
-queue-name.describe=Queue Name
-total-submitted.describe=Total submitted Tasks
-total-completed.describe=Total Completed Tasks
-highest-active-threads.describe=Highest active threads
-active-threads.describe=Number of Active Threads
\ No newline at end of file
Modified: branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -535,81 +535,6 @@
}
}
- private void clearPlanCache(){
- LogManager.logInfo(LogConstants.CTX_DQP, QueryPlugin.Util.getString("DQPCore.Clearing_prepared_plan_cache")); //$NON-NLS-1$
- this.prepPlanCache.clearAll();
- }
-
- private void clearResultSetCache() {
- //clear cache in server
- if(rsCache != null){
- rsCache.clearAll();
- }
- }
-
- private void clearPlanCache(String vdbName, int version){
- LogManager.logInfo(LogConstants.CTX_DQP, QueryPlugin.Util.getString("DQPCore.Clearing_prepared_plan_cache_for_vdb", vdbName, version)); //$NON-NLS-1$
- this.prepPlanCache.clearForVDB(vdbName, version);
- }
-
- private void clearResultSetCache(String vdbName, int version) {
- //clear cache in server
- if(rsCache != null){
- LogManager.logInfo(LogConstants.CTX_DQP, QueryPlugin.Util.getString("DQPCore.clearing_resultset_cache", vdbName, version)); //$NON-NLS-1$
- rsCache.clearForVDB(vdbName, version);
- }
- }
-
- public CacheStatisticsMetadata getCacheStatistics(String cacheType) {
- if (cacheType.equalsIgnoreCase(Admin.Cache.PREPARED_PLAN_CACHE.toString())) {
- return buildCacheStats(Admin.Cache.PREPARED_PLAN_CACHE.toString(), this.prepPlanCache);
- }
- else if (cacheType.equalsIgnoreCase(Admin.Cache.QUERY_SERVICE_RESULT_SET_CACHE.toString())) {
- return buildCacheStats(Admin.Cache.QUERY_SERVICE_RESULT_SET_CACHE.toString(), this.rsCache);
- }
- return null;
- }
-
- private CacheStatisticsMetadata buildCacheStats(String name, SessionAwareCache cache) {
- CacheStatisticsMetadata stats = new CacheStatisticsMetadata();
- stats.setName(name);
- stats.setHitRatio(cache.getRequestCount() == 0?0:((double)cache.getCacheHitCount()/cache.getRequestCount())*100);
- stats.setTotalEntries(cache.getTotalCacheEntries());
- stats.setRequestCount(cache.getRequestCount());
- return stats;
- }
-
- public Collection<String> getCacheTypes(){
- ArrayList<String> caches = new ArrayList<String>();
- caches.add(Admin.Cache.PREPARED_PLAN_CACHE.toString());
- caches.add(Admin.Cache.QUERY_SERVICE_RESULT_SET_CACHE.toString());
- return caches;
- }
-
- public void clearCache(String cacheType) {
- Admin.Cache cache = Admin.Cache.valueOf(cacheType);
- switch (cache) {
- case PREPARED_PLAN_CACHE:
- clearPlanCache();
- break;
- case QUERY_SERVICE_RESULT_SET_CACHE:
- clearResultSetCache();
- break;
- }
- }
-
- public void clearCache(String cacheType, String vdbName, int version) {
- Admin.Cache cache = Admin.Cache.valueOf(cacheType);
- switch (cache) {
- case PREPARED_PLAN_CACHE:
- clearPlanCache(vdbName, version);
- break;
- case QUERY_SERVICE_RESULT_SET_CACHE:
- clearResultSetCache(vdbName, version);
- break;
- }
- }
-
public Collection<TransactionMetadata> getTransactions() {
return this.transactionService.getTransactions();
}
Modified: branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java
===================================================================
--- branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -23,12 +23,10 @@
package org.teiid.dqp.internal.process;
import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
+import org.teiid.adminapi.Admin;
import org.teiid.cache.Cachable;
import org.teiid.cache.Cache;
import org.teiid.cache.CacheConfiguration;
@@ -338,4 +336,15 @@
}
return this.distributedCache.keys();
}
+
+ public static Collection<String> getCacheTypes(){
+ ArrayList<String> caches = new ArrayList<String>();
+ caches.add(Admin.Cache.PREPARED_PLAN_CACHE.toString());
+ caches.add(Admin.Cache.QUERY_SERVICE_RESULT_SET_CACHE.toString());
+ return caches;
+ }
+
+ public static boolean isResultsetCache(String cacheType) {
+ return (Admin.Cache.valueOf(cacheType) == Admin.Cache.QUERY_SERVICE_RESULT_SET_CACHE);
+ }
}
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/BaseOperationHandler.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/BaseOperationHandler.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/BaseOperationHandler.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -59,12 +59,10 @@
context.addStep(new OperationStepHandler() {
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
- ModelNode model = context.getResult();
-
final ModelNode address = operation.require(OP_ADDR);
final PathAddress pathAddress = PathAddress.pathAddress(address);
- executeOperation(getService(context, pathAddress), operation, model);
+ executeOperation(context, getService(context, pathAddress, operation), operation);
context.completeStep();
}
@@ -78,7 +76,7 @@
}
@SuppressWarnings("unused")
- protected T getService(OperationContext context, PathAddress pathAddress) throws OperationFailedException{
+ protected T getService(OperationContext context, PathAddress pathAddress, ModelNode operation) throws OperationFailedException{
return null;
}
@@ -92,15 +90,15 @@
return operation;
}
- protected String getReplyName() {
- return name()+".reply"+DESCRIBE; //$NON-NLS-1$
- }
+// protected String getReplyName() {
+// return name()+".reply"+DESCRIBE; //$NON-NLS-1$
+// }
protected String getParameterDescription(ResourceBundle bundle, String paramName) {
return bundle.getString(name()+"."+paramName+DESCRIBE); //$NON-NLS-1$
}
- abstract protected void executeOperation(T service, ModelNode operation, ModelNode node) throws OperationFailedException;
+ abstract protected void executeOperation(OperationContext context, T service, ModelNode operation) throws OperationFailedException;
protected void describeParameters(@SuppressWarnings("unused") ModelNode operationNode, @SuppressWarnings("unused")ResourceBundle bundle) {
}
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/ObjectSerializer.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/ObjectSerializer.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/ObjectSerializer.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -83,6 +83,10 @@
public File buildVDBFile(VDBMetaData vdb) {
return new File(baseDirectory(vdb.getName()+"_"+vdb.getVersion()), vdb.getName()+"_"+vdb.getVersion()+ATTACHMENT_SUFFIX); //$NON-NLS-1$ //$NON-NLS-2$
}
+
+ public File buildVdbXml(VDBMetaData vdb) {
+ return new File(baseDirectory(vdb.getName()+"_"+vdb.getVersion()), "vdb.xml"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
public File buildModelFile(VDBMetaData vdb, String modelName) {
return new File(baseDirectory(vdb.getName()+"_"+vdb.getVersion()), vdb.getName()+"_"+vdb.getVersion()+"_"+modelName+ATTACHMENT_SUFFIX); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@@ -114,5 +118,11 @@
}
cacheFile.delete();
return null;
+ }
+
+ public OutputStream getVdbXmlOutputStream(VDBMetaData vdb) throws IOException {
+ File f = buildVdbXml(vdb);
+ f.mkdirs();
+ return new FileOutputStream(f);
}
}
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/OperationsConstants.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/OperationsConstants.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/OperationsConstants.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -28,6 +28,12 @@
public static final String EXECUTION_ID = "execution-id";//$NON-NLS-1$
public static final String CACHE_TYPE = "cache-type";//$NON-NLS-1$
public static final String XID = "xid";//$NON-NLS-1$
+ public static final String DATA_ROLE = "data-role"; //$NON-NLS-1$
+ public static final String MAPPED_ROLE = "mapped-role"; //$NON-NLS-1$
+ public static final String CONNECTION_TYPE = "connection-type"; //$NON-NLS-1$
+ public static final String MODEL_NAME = "model-name"; //$NON-NLS-1$
+ public static final String SOURCE_NAME = "source-name"; //$NON-NLS-1$
+ public static final String DS_NAME = "ds-name"; //$NON-NLS-1$
public static final String SOURCE_VDBNAME = "source-vdb-name";//$NON-NLS-1$
public static final String SOURCE_VDBVERSION = "source-vdb-version";//$NON-NLS-1$
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/QueryEngineOperationHandler.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/QueryEngineOperationHandler.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/QueryEngineOperationHandler.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -33,13 +33,19 @@
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.jboss.msc.service.ServiceController;
+import org.teiid.adminapi.Admin;
import org.teiid.adminapi.AdminException;
+import org.teiid.adminapi.AdminProcessingException;
+import org.teiid.adminapi.VDB;
import org.teiid.adminapi.impl.*;
-import org.teiid.adminapi.impl.MetadataMapper.TransactionMetadataMapper;
-import org.teiid.adminapi.impl.MetadataMapper.VDBTranslatorMetaDataMapper;
+import org.teiid.adminapi.impl.VDBMetadataMapper.TransactionMetadataMapper;
+import org.teiid.adminapi.impl.VDBMetadataMapper.VDBTranslatorMetaDataMapper;
import org.teiid.deployers.VDBRepository;
import org.teiid.dqp.internal.datamgr.TranslatorRepository;
+import org.teiid.dqp.internal.process.SessionAwareCache;
import org.teiid.jboss.deployers.RuntimeEngineDeployer;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
abstract class QueryEngineOperationHandler extends BaseOperationHandler<RuntimeEngineDeployer> {
@@ -48,7 +54,7 @@
}
@Override
- protected RuntimeEngineDeployer getService(OperationContext context, PathAddress pathAddress) throws OperationFailedException {
+ protected RuntimeEngineDeployer getService(OperationContext context, PathAddress pathAddress, ModelNode operation) throws OperationFailedException {
String serviceName = pathAddress.getLastElement().getValue();
ServiceController<?> sc = context.getServiceRegistry(false).getRequiredService(TeiidServiceNames.engineServiceName(serviceName));
return RuntimeEngineDeployer.class.cast(sc.getValue());
@@ -62,7 +68,7 @@
}
@Override
- public TranslatorRepository getService(OperationContext context, PathAddress pathAddress) throws OperationFailedException {
+ public TranslatorRepository getService(OperationContext context, PathAddress pathAddress, ModelNode operation) throws OperationFailedException {
ServiceController<?> sc = context.getServiceRegistry(false).getRequiredService(TeiidServiceNames.TRANSLATOR_REPO);
return TranslatorRepository.class.cast(sc.getValue());
}
@@ -73,12 +79,11 @@
super(operationName);
}
@Override
- protected void executeOperation(RuntimeEngineDeployer engine, ModelNode operation, ModelNode node) throws OperationFailedException{
- node.set(engine.getRuntimeVersion());
+ protected void executeOperation(OperationContext context, RuntimeEngineDeployer engine, ModelNode operation) throws OperationFailedException{
+ context.getResult().set(engine.getRuntimeVersion());
}
protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
operationNode.get(REPLY_PROPERTIES).set(ModelType.STRING);
- operationNode.get(REPLY_PROPERTIES, DESCRIBE).set(bundle.getString(getReplyName()));
}
}
@@ -87,52 +92,53 @@
super(operationName);
}
@Override
- protected void executeOperation(RuntimeEngineDeployer engine, ModelNode operation, ModelNode node) throws OperationFailedException{
+ protected void executeOperation(OperationContext context, RuntimeEngineDeployer engine, ModelNode operation) throws OperationFailedException{
try {
- node.set(String.valueOf(engine.getActiveSessionsCount()));
+ context.getResult().set(String.valueOf(engine.getActiveSessionsCount()));
} catch (AdminException e) {
- // TODO: handle exception in model node terms
+ throw new OperationFailedException(new ModelNode().set(e.getMessage()));
}
}
protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
operationNode.get(REPLY_PROPERTIES).set(ModelType.INT);
- operationNode.get(REPLY_PROPERTIES, DESCRIBE).set(bundle.getString(getReplyName()));
}
}
-class GetActiveSessions extends QueryEngineOperationHandler{
- protected GetActiveSessions() {
- super("active-sessions"); //$NON-NLS-1$
+class ListSessions extends QueryEngineOperationHandler{
+ protected ListSessions() {
+ super("list-sessions"); //$NON-NLS-1$
}
@Override
- protected void executeOperation(RuntimeEngineDeployer engine, ModelNode operation, ModelNode node) throws OperationFailedException{
+ protected void executeOperation(OperationContext context, RuntimeEngineDeployer engine, ModelNode operation) throws OperationFailedException{
try {
+ ModelNode result = context.getResult();
Collection<SessionMetadata> sessions = engine.getActiveSessions();
for (SessionMetadata session:sessions) {
- MetadataMapper.SessionMetadataMapper.wrap(session, node.add());
+ VDBMetadataMapper.SessionMetadataMapper.INSTANCE.wrap(session, result.add());
}
} catch (AdminException e) {
- // TODO: handle exception in model node terms
+ throw new OperationFailedException(new ModelNode().set(e.getMessage()));
}
}
protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
- operationNode.get(REPLY_PROPERTIES).add(MetadataMapper.SessionMetadataMapper.describe(new ModelNode()));
+ operationNode.get(REPLY_PROPERTIES).add(VDBMetadataMapper.SessionMetadataMapper.INSTANCE.describe(new ModelNode()));
}
}
-class GetRequestsPerSession extends QueryEngineOperationHandler{
- protected GetRequestsPerSession() {
+class RequestsPerSession extends QueryEngineOperationHandler{
+ protected RequestsPerSession() {
super("requests-per-session"); //$NON-NLS-1$
}
@Override
- protected void executeOperation(RuntimeEngineDeployer engine, ModelNode operation, ModelNode node) throws OperationFailedException{
+ protected void executeOperation(OperationContext context, RuntimeEngineDeployer engine, ModelNode operation) throws OperationFailedException{
if (!operation.hasDefined(OperationsConstants.SESSION)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.SESSION+MISSING)));
}
+ ModelNode result = context.getResult();
List<RequestMetadata> requests = engine.getRequestsForSession(operation.get(OperationsConstants.SESSION).asString());
for (RequestMetadata request:requests) {
- MetadataMapper.RequestMetadataMapper.wrap(request, node.add());
+ VDBMetadataMapper.RequestMetadataMapper.INSTANCE.wrap(request, result.add());
}
}
@@ -141,16 +147,33 @@
operationNode.get(REQUEST_PROPERTIES, OperationsConstants.SESSION, REQUIRED).set(true);
operationNode.get(REQUEST_PROPERTIES, OperationsConstants.SESSION, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.SESSION));
- operationNode.get(REPLY_PROPERTIES).add(MetadataMapper.RequestMetadataMapper.describe(new ModelNode()));
+ operationNode.get(REPLY_PROPERTIES).add(VDBMetadataMapper.RequestMetadataMapper.INSTANCE.describe(new ModelNode()));
}
}
-class GetRequestsPerVDB extends QueryEngineOperationHandler{
- protected GetRequestsPerVDB() {
+class ListRequests extends QueryEngineOperationHandler{
+ protected ListRequests() {
+ super("list-requests"); //$NON-NLS-1$
+ }
+ @Override
+ protected void executeOperation(OperationContext context, RuntimeEngineDeployer engine, ModelNode operation) throws OperationFailedException{
+ ModelNode result = context.getResult();
+ List<RequestMetadata> requests = engine.getRequests();
+ for (RequestMetadata request:requests) {
+ VDBMetadataMapper.RequestMetadataMapper.INSTANCE.wrap(request, result.add());
+ }
+ }
+ protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
+ operationNode.get(REPLY_PROPERTIES).add(VDBMetadataMapper.RequestMetadataMapper.INSTANCE.describe(new ModelNode()));
+ }
+}
+
+class RequestsPerVDB extends QueryEngineOperationHandler{
+ protected RequestsPerVDB() {
super("requests-per-vdb"); //$NON-NLS-1$
}
@Override
- protected void executeOperation(RuntimeEngineDeployer engine, ModelNode operation, ModelNode node) throws OperationFailedException{
+ protected void executeOperation(OperationContext context, RuntimeEngineDeployer engine, ModelNode operation) throws OperationFailedException{
try {
if (!operation.hasDefined(OperationsConstants.VDB_NAME)) {
@@ -159,12 +182,13 @@
if (!operation.hasDefined(OperationsConstants.VDB_VERSION)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.VDB_VERSION+MISSING)));
}
-
+
+ ModelNode result = context.getResult();
String vdbName = operation.get(OperationsConstants.VDB_NAME).asString();
int vdbVersion = operation.get(OperationsConstants.VDB_VERSION).asInt();
List<RequestMetadata> requests = engine.getRequestsUsingVDB(vdbName,vdbVersion);
for (RequestMetadata request:requests) {
- MetadataMapper.RequestMetadataMapper.wrap(request, node.add());
+ VDBMetadataMapper.RequestMetadataMapper.INSTANCE.wrap(request, result.add());
}
} catch (AdminException e) {
throw new OperationFailedException(e, new ModelNode().set(e.getMessage()));
@@ -180,7 +204,7 @@
operationNode.get(REQUEST_PROPERTIES, OperationsConstants.VDB_VERSION, REQUIRED).set(true);
operationNode.get(REQUEST_PROPERTIES, OperationsConstants.VDB_VERSION, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.VDB_VERSION));
- operationNode.get(REPLY_PROPERTIES).add(MetadataMapper.RequestMetadataMapper.describe(new ModelNode()));
+ operationNode.get(REPLY_PROPERTIES).add(VDBMetadataMapper.RequestMetadataMapper.INSTANCE.describe(new ModelNode()));
}
}
@@ -189,14 +213,15 @@
super("long-running-queries"); //$NON-NLS-1$
}
@Override
- protected void executeOperation(RuntimeEngineDeployer engine, ModelNode operation, ModelNode node) throws OperationFailedException{
+ protected void executeOperation(OperationContext context, RuntimeEngineDeployer engine, ModelNode operation) throws OperationFailedException{
+ ModelNode result = context.getResult();
List<RequestMetadata> requests = engine.getLongRunningRequests();
for (RequestMetadata request:requests) {
- MetadataMapper.RequestMetadataMapper.wrap(request, node.add());
+ VDBMetadataMapper.RequestMetadataMapper.INSTANCE.wrap(request, result.add());
}
}
protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
- operationNode.get(REPLY_PROPERTIES).add(MetadataMapper.RequestMetadataMapper.describe(new ModelNode()));
+ operationNode.get(REPLY_PROPERTIES).add(VDBMetadataMapper.RequestMetadataMapper.INSTANCE.describe(new ModelNode()));
}
}
@@ -205,7 +230,7 @@
super("terminate-session"); //$NON-NLS-1$
}
@Override
- protected void executeOperation(RuntimeEngineDeployer engine, ModelNode operation, ModelNode node) throws OperationFailedException{
+ protected void executeOperation(OperationContext context, RuntimeEngineDeployer engine, ModelNode operation) throws OperationFailedException{
if (!operation.hasDefined(OperationsConstants.SESSION)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.SESSION+MISSING)));
}
@@ -219,18 +244,22 @@
}
}
-class CancelQuery extends QueryEngineOperationHandler{
- protected CancelQuery() {
- super("cancel-query"); //$NON-NLS-1$
+class CancelRequest extends QueryEngineOperationHandler{
+ protected CancelRequest() {
+ super("cancel-request"); //$NON-NLS-1$
}
@Override
- protected void executeOperation(RuntimeEngineDeployer engine, ModelNode operation, ModelNode node) throws OperationFailedException{
+ protected void executeOperation(OperationContext context, RuntimeEngineDeployer engine, ModelNode operation) throws OperationFailedException{
try {
if (!operation.hasDefined(OperationsConstants.SESSION)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.SESSION+MISSING)));
}
+ if (!operation.hasDefined(OperationsConstants.EXECUTION_ID)) {
+ throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.EXECUTION_ID+MISSING)));
+ }
boolean pass = engine.cancelRequest(operation.get(OperationsConstants.SESSION).asString(), operation.get(OperationsConstants.EXECUTION_ID).asLong());
- node.set(pass);
+ ModelNode result = context.getResult();
+ result.set(pass);
} catch (AdminException e) {
throw new OperationFailedException(e, new ModelNode().set(e.getMessage()));
}
@@ -246,19 +275,47 @@
operationNode.get(REQUEST_PROPERTIES, OperationsConstants.EXECUTION_ID, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.EXECUTION_ID));
operationNode.get(REPLY_PROPERTIES).set(ModelType.BOOLEAN);
- operationNode.get(REPLY_PROPERTIES, DESCRIBE).set(bundle.getString(getReplyName()));
}
}
-class CacheTypes extends QueryEngineOperationHandler{
+abstract class BaseCachehandler extends BaseOperationHandler<SessionAwareCache>{
+ BaseCachehandler(String operationName){
+ super(operationName);
+ }
+
+ @Override
+ protected SessionAwareCache getService(OperationContext context, PathAddress pathAddress, ModelNode operation) throws OperationFailedException {
+ String cacheType = Admin.Cache.QUERY_SERVICE_RESULT_SET_CACHE.name();
+
+ if (operation.hasDefined(OperationsConstants.CACHE_TYPE)) {
+ cacheType = operation.get(OperationsConstants.CACHE_TYPE).asString();
+ //throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.CACHE_TYPE+MISSING)));
+ }
+
+ ServiceController<?> sc;
+ if (SessionAwareCache.isResultsetCache(cacheType)) {
+ sc = context.getServiceRegistry(false).getRequiredService(TeiidServiceNames.CACHE_RESULTSET);
+ }
+ else {
+ sc = context.getServiceRegistry(false).getRequiredService(TeiidServiceNames.CACHE_PREPAREDPLAN);
+ }
+
+ return SessionAwareCache.class.cast(sc.getValue());
+ }
+}
+
+
+class CacheTypes extends BaseCachehandler {
protected CacheTypes() {
super("cache-types"); //$NON-NLS-1$
}
+
@Override
- protected void executeOperation(RuntimeEngineDeployer engine, ModelNode operation, ModelNode node) throws OperationFailedException {
- Collection<String> types = engine.getCacheTypes();
+ protected void executeOperation(OperationContext context, SessionAwareCache cache, ModelNode operation) throws OperationFailedException {
+ ModelNode result = context.getResult();
+ Collection<String> types = SessionAwareCache.getCacheTypes();
for (String type:types) {
- node.add(type);
+ result.add(type);
}
}
@@ -271,27 +328,28 @@
}
}
-class ClearCache extends QueryEngineOperationHandler{
+class ClearCache extends BaseCachehandler {
protected ClearCache() {
super("clear-cache"); //$NON-NLS-1$
}
+
@Override
- protected void executeOperation(RuntimeEngineDeployer engine, ModelNode operation, ModelNode node) throws OperationFailedException {
-
- if (!operation.hasDefined(OperationsConstants.CACHE_TYPE)) {
+ protected void executeOperation(OperationContext context, SessionAwareCache cache, ModelNode operation) throws OperationFailedException {
+ if (operation.hasDefined(OperationsConstants.CACHE_TYPE)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.CACHE_TYPE+MISSING)));
}
-
+
String cacheType = operation.get(OperationsConstants.CACHE_TYPE).asString();
-
- if (operation.get(OperationsConstants.VDB_NAME) != null && operation.get(OperationsConstants.VDB_VERSION) != null) {
+ if (operation.hasDefined(OperationsConstants.VDB_NAME) && operation.hasDefined(OperationsConstants.VDB_VERSION)) {
String vdbName = operation.get(OperationsConstants.VDB_NAME).asString();
int vdbVersion = operation.get(OperationsConstants.VDB_VERSION).asInt();
- engine.clearCache(cacheType, vdbName, vdbVersion);
+ LogManager.logInfo(LogConstants.CTX_DQP, IntegrationPlugin.Util.getString("clearing_cache_vdb", cacheType, vdbName, vdbVersion)); //$NON-NLS-1$
+ cache.clearForVDB(vdbName, vdbVersion);
}
else {
- engine.clearCache(cacheType);
+ LogManager.logInfo(LogConstants.CTX_DQP, IntegrationPlugin.Util.getString("clearing_cache", cacheType)); //$NON-NLS-1$
+ cache.clearAll();
}
}
@@ -311,28 +369,39 @@
}
}
-class CacheStatistics extends QueryEngineOperationHandler{
+class CacheStatistics extends BaseCachehandler {
protected CacheStatistics() {
super("cache-statistics"); //$NON-NLS-1$
}
+
@Override
- protected void executeOperation(RuntimeEngineDeployer engine, ModelNode operation, ModelNode node) throws OperationFailedException {
+ protected void executeOperation(OperationContext context, SessionAwareCache cache, ModelNode operation) throws OperationFailedException {
if (!operation.hasDefined(OperationsConstants.CACHE_TYPE)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.CACHE_TYPE+MISSING)));
}
+ ModelNode result = context.getResult();
String cacheType = operation.get(OperationsConstants.CACHE_TYPE).asString();
- CacheStatisticsMetadata stats = engine.getCacheStatistics(cacheType);
- MetadataMapper.CacheStatisticsMetadataMapper.wrap(stats, node);
+ CacheStatisticsMetadata stats = buildCacheStats(cacheType, cache);
+ VDBMetadataMapper.CacheStatisticsMetadataMapper.INSTANCE.wrap(stats, result);
}
+ private CacheStatisticsMetadata buildCacheStats(String name, SessionAwareCache cache) {
+ CacheStatisticsMetadata stats = new CacheStatisticsMetadata();
+ stats.setName(name);
+ stats.setHitRatio(cache.getRequestCount() == 0?0:((double)cache.getCacheHitCount()/cache.getRequestCount())*100);
+ stats.setTotalEntries(cache.getTotalCacheEntries());
+ stats.setRequestCount(cache.getRequestCount());
+ return stats;
+ }
+
protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
operationNode.get(REQUEST_PROPERTIES, OperationsConstants.CACHE_TYPE, TYPE).set(ModelType.STRING);
operationNode.get(REQUEST_PROPERTIES, OperationsConstants.CACHE_TYPE, REQUIRED).set(true);
operationNode.get(REQUEST_PROPERTIES, OperationsConstants.CACHE_TYPE, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.CACHE_TYPE));
ModelNode node = new ModelNode();
- operationNode.get(REPLY_PROPERTIES).add(MetadataMapper.CacheStatisticsMetadataMapper.describe(node));
+ operationNode.get(REPLY_PROPERTIES).add(VDBMetadataMapper.CacheStatisticsMetadataMapper.INSTANCE.describe(node));
}
}
@@ -342,30 +411,32 @@
super("workerpool-statistics"); //$NON-NLS-1$
}
@Override
- protected void executeOperation(RuntimeEngineDeployer engine, ModelNode operation, ModelNode node) throws OperationFailedException {
+ protected void executeOperation(OperationContext context, RuntimeEngineDeployer engine, ModelNode operation) throws OperationFailedException {
+ ModelNode result = context.getResult();
WorkerPoolStatisticsMetadata stats = engine.getWorkerPoolStatistics();
- MetadataMapper.WorkerPoolStatisticsMetadataMapper.wrap(stats, node);
+ VDBMetadataMapper.WorkerPoolStatisticsMetadataMapper.INSTANCE.wrap(stats, result);
}
protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
- operationNode.get(REPLY_PROPERTIES).add(MetadataMapper.WorkerPoolStatisticsMetadataMapper.describe(new ModelNode()));
+ operationNode.get(REPLY_PROPERTIES).add(VDBMetadataMapper.WorkerPoolStatisticsMetadataMapper.INSTANCE.describe(new ModelNode()));
}
}
-class ActiveTransactions extends QueryEngineOperationHandler{
+class ListTransactions extends QueryEngineOperationHandler{
- protected ActiveTransactions() {
- super("active-transactions"); //$NON-NLS-1$
+ protected ListTransactions() {
+ super("list-transactions"); //$NON-NLS-1$
}
@Override
- protected void executeOperation(RuntimeEngineDeployer engine, ModelNode operation, ModelNode node) throws OperationFailedException {
+ protected void executeOperation(OperationContext context, RuntimeEngineDeployer engine, ModelNode operation) throws OperationFailedException {
+ ModelNode result = context.getResult();
Collection<TransactionMetadata> txns = engine.getTransactions();
for (TransactionMetadata txn:txns) {
- MetadataMapper.TransactionMetadataMapper.wrap(txn, node.add());
+ VDBMetadataMapper.TransactionMetadataMapper.INSTANCE.wrap(txn, result.add());
}
}
protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
ModelNode node = new ModelNode();
- operationNode.get(REPLY_PROPERTIES).add(TransactionMetadataMapper.describe(node));
+ operationNode.get(REPLY_PROPERTIES).add(TransactionMetadataMapper.INSTANCE.describe(node));
}
}
@@ -375,7 +446,7 @@
super("terminate-transaction"); //$NON-NLS-1$
}
@Override
- protected void executeOperation(RuntimeEngineDeployer engine, ModelNode operation, ModelNode node) throws OperationFailedException {
+ protected void executeOperation(OperationContext context, RuntimeEngineDeployer engine, ModelNode operation) throws OperationFailedException {
if (!operation.hasDefined(OperationsConstants.XID)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.XID+MISSING)));
@@ -403,13 +474,13 @@
}
@Override
- protected VDBRepository getService(OperationContext context, PathAddress pathAddress) throws OperationFailedException {
+ protected VDBRepository getService(OperationContext context, PathAddress pathAddress, ModelNode operation) throws OperationFailedException {
ServiceController<?> sc = context.getServiceRegistry(false).getRequiredService(TeiidServiceNames.VDB_REPO);
return VDBRepository.class.cast(sc.getValue());
}
@Override
- protected void executeOperation(VDBRepository repo, ModelNode operation, ModelNode node) throws OperationFailedException {
+ protected void executeOperation(OperationContext context, VDBRepository repo, ModelNode operation) throws OperationFailedException {
if (!operation.hasDefined(OperationsConstants.SOURCE_VDBNAME)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.SOURCE_VDBNAME+MISSING)));
}
@@ -460,7 +531,7 @@
super("execute-query"); //$NON-NLS-1$
}
@Override
- protected void executeOperation(RuntimeEngineDeployer engine, ModelNode operation, ModelNode node) throws OperationFailedException {
+ protected void executeOperation(OperationContext context, RuntimeEngineDeployer engine, ModelNode operation) throws OperationFailedException {
if (!operation.hasDefined(OperationsConstants.VDB_NAME)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.VDB_NAME+MISSING)));
@@ -475,6 +546,7 @@
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.TIMEOUT_IN_MILLI+MISSING)));
}
+ ModelNode result = context.getResult();
String vdbName = operation.get(OperationsConstants.VDB_NAME).asString();
int vdbVersion = operation.get(OperationsConstants.VDB_VERSION).asInt();
String sql = operation.get(OperationsConstants.SQL_QUERY).asString();
@@ -492,7 +564,7 @@
//TODO: support in native types instead of string here.
rowNode.get(ATTRIBUTES, colNames.get(colNum).toString()).set(row.get(colNum).toString());
}
- node.add(rowNode);
+ result.add(rowNode);
}
} catch (AdminException e) {
throw new OperationFailedException(new ModelNode().set(e.getMessage()));
@@ -527,13 +599,13 @@
}
@Override
- protected VDBRepository getService(OperationContext context, PathAddress pathAddress) throws OperationFailedException {
+ protected VDBRepository getService(OperationContext context, PathAddress pathAddress, ModelNode operation) throws OperationFailedException {
ServiceController<?> sc = context.getServiceRegistry(false).getRequiredService(TeiidServiceNames.VDB_REPO);
return VDBRepository.class.cast(sc.getValue());
}
@Override
- protected void executeOperation(VDBRepository repo, ModelNode operation, ModelNode node) throws OperationFailedException {
+ protected void executeOperation(OperationContext context, VDBRepository repo, ModelNode operation) throws OperationFailedException {
if (!operation.hasDefined(OperationsConstants.VDB_NAME)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.VDB_NAME+MISSING)));
}
@@ -541,11 +613,12 @@
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.VDB_VERSION+MISSING)));
}
+ ModelNode result = context.getResult();
String vdbName = operation.get(OperationsConstants.VDB_NAME).asString();
int vdbVersion = operation.get(OperationsConstants.VDB_VERSION).asInt();
VDBMetaData vdb = repo.getVDB(vdbName, vdbVersion);
- MetadataMapper.wrap(vdb, node);
+ VDBMetadataMapper.INSTANCE.wrap(vdb, result);
}
protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
@@ -557,7 +630,7 @@
operationNode.get(REQUEST_PROPERTIES, OperationsConstants.VDB_VERSION, REQUIRED).set(true);
operationNode.get(REQUEST_PROPERTIES, OperationsConstants.VDB_VERSION, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.VDB_VERSION));
- operationNode.get(REPLY_PROPERTIES).set(MetadataMapper.describe(new ModelNode()));
+ operationNode.get(REPLY_PROPERTIES).set(VDBMetadataMapper.INSTANCE.describe(new ModelNode()));
}
}
@@ -568,40 +641,41 @@
}
@Override
- protected VDBRepository getService(OperationContext context, PathAddress pathAddress) throws OperationFailedException {
+ protected VDBRepository getService(OperationContext context, PathAddress pathAddress, ModelNode operation) throws OperationFailedException {
ServiceController<?> sc = context.getServiceRegistry(false).getRequiredService(TeiidServiceNames.VDB_REPO);
return VDBRepository.class.cast(sc.getValue());
}
@Override
- protected void executeOperation(VDBRepository repo, ModelNode operation, ModelNode node) throws OperationFailedException {
+ protected void executeOperation(OperationContext context, VDBRepository repo, ModelNode operation) throws OperationFailedException {
+ ModelNode result = context.getResult();
List<VDBMetaData> vdbs = repo.getVDBs();
for (VDBMetaData vdb:vdbs) {
- MetadataMapper.wrap(vdb, node.add());
+ VDBMetadataMapper.INSTANCE.wrap(vdb, result.add());
}
}
protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
- operationNode.get(REPLY_PROPERTIES).add(MetadataMapper.describe(new ModelNode()));
+ operationNode.get(REPLY_PROPERTIES).add(VDBMetadataMapper.INSTANCE.describe(new ModelNode()));
}
}
-class GetTranslators extends TranslatorOperationHandler{
+class ListTranslators extends TranslatorOperationHandler{
- protected GetTranslators() {
+ protected ListTranslators() {
super("list-translators"); //$NON-NLS-1$
}
@Override
- protected void executeOperation(TranslatorRepository repo, ModelNode operation, ModelNode node) throws OperationFailedException {
+ protected void executeOperation(OperationContext context, TranslatorRepository repo, ModelNode operation) throws OperationFailedException {
+ ModelNode result = context.getResult();
List<VDBTranslatorMetaData> translators = repo.getTranslators();
for (VDBTranslatorMetaData t:translators) {
- MetadataMapper.VDBTranslatorMetaDataMapper.wrap(t, node.add());
+ VDBMetadataMapper.VDBTranslatorMetaDataMapper.INSTANCE.wrap(t, result.add());
}
}
protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
- operationNode.get(REPLY_PROPERTIES, DESCRIPTION).set(bundle.getString(getReplyName()));
- operationNode.get(REPLY_PROPERTIES).add(MetadataMapper.VDBTranslatorMetaDataMapper.describe(new ModelNode()));
+ operationNode.get(REPLY_PROPERTIES).add(VDBMetadataMapper.VDBTranslatorMetaDataMapper.INSTANCE.describe(new ModelNode()));
}
}
@@ -612,16 +686,16 @@
}
@Override
- protected void executeOperation(TranslatorRepository repo, ModelNode operation, ModelNode node) throws OperationFailedException {
+ protected void executeOperation(OperationContext context, TranslatorRepository repo, ModelNode operation) throws OperationFailedException {
if (!operation.hasDefined(OperationsConstants.TRANSLATOR_NAME)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.TRANSLATOR_NAME+MISSING)));
}
+ ModelNode result = context.getResult();
String translatorName = operation.get(OperationsConstants.TRANSLATOR_NAME).asString();
-
VDBTranslatorMetaData translator = repo.getTranslatorMetaData(translatorName);
- MetadataMapper.VDBTranslatorMetaDataMapper.wrap(translator, node);
+ VDBMetadataMapper.VDBTranslatorMetaDataMapper.INSTANCE.wrap(translator, result);
}
protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
@@ -629,36 +703,270 @@
operationNode.get(REQUEST_PROPERTIES, OperationsConstants.TRANSLATOR_NAME, REQUIRED).set(true);
operationNode.get(REQUEST_PROPERTIES, OperationsConstants.TRANSLATOR_NAME, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.TRANSLATOR_NAME));
- operationNode.get(REPLY_PROPERTIES).set(VDBTranslatorMetaDataMapper.describe(new ModelNode()));
- operationNode.get(REPLY_PROPERTIES, DESCRIPTION).set(bundle.getString(getReplyName()));
+ operationNode.get(REPLY_PROPERTIES).set(VDBTranslatorMetaDataMapper.INSTANCE.describe(new ModelNode()));
}
}
-class ListQueryEngines extends TranslatorOperationHandler{
+abstract class VDBOperations extends BaseOperationHandler<VDBService>{
+ public VDBOperations(String operationName) {
+ super(operationName);
+ }
+ @Override
+ public VDBService getService(OperationContext context, PathAddress pathAddress, ModelNode operation) throws OperationFailedException {
+ if (!operation.hasDefined(OperationsConstants.VDB_NAME)) {
+ throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.VDB_NAME+MISSING)));
+ }
+
+ if (!operation.hasDefined(OperationsConstants.VDB_VERSION)) {
+ throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.VDB_VERSION+MISSING)));
+ }
+
+ String vdbName = operation.get(OperationsConstants.VDB_NAME).asString();
+ int vdbVersion = operation.get(OperationsConstants.VDB_VERSION).asInt();
+ ServiceController<?> sc = context.getServiceRegistry(false).getRequiredService(TeiidServiceNames.vdbServiceName(vdbName, vdbVersion));
+ return VDBService.class.cast(sc.getValue());
+ }
- protected ListQueryEngines() {
- super("list-engines"); //$NON-NLS-1$
+ protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.VDB_NAME, TYPE).set(ModelType.STRING);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.VDB_NAME, REQUIRED).set(true);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.VDB_NAME, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.VDB_NAME));
+
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.VDB_VERSION, TYPE).set(ModelType.STRING);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.VDB_VERSION, REQUIRED).set(true);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.VDB_VERSION, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.VDB_VERSION));
+ }
+}
+
+class AddDataRole extends VDBOperations {
+
+ public AddDataRole() {
+ super("add-data-role"); //$NON-NLS-1$
}
@Override
- protected void executeOperation(TranslatorRepository repo, ModelNode operation, ModelNode node) throws OperationFailedException {
+ protected void executeOperation(OperationContext context, VDBService service, ModelNode operation) throws OperationFailedException {
+ if (!operation.hasDefined(OperationsConstants.DATA_ROLE)) {
+ throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.DATA_ROLE+MISSING)));
+ }
+
+ if (!operation.hasDefined(OperationsConstants.MAPPED_ROLE)) {
+ throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.MAPPED_ROLE+MISSING)));
+ }
+
+ String dataRole = operation.get(OperationsConstants.DATA_ROLE).asString();
+ String mappedRole = operation.get(OperationsConstants.MAPPED_ROLE).asString();
+ try {
+ service.addDataRole(dataRole, mappedRole);
+ } catch (AdminProcessingException e) {
+ throw new OperationFailedException(new ModelNode().set(e.getMessage()));
+ }
+ }
+
+ @Override
+ protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
+ super.describeParameters(operationNode, bundle);
+
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.DATA_ROLE, TYPE).set(ModelType.STRING);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.DATA_ROLE, REQUIRED).set(true);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.DATA_ROLE, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.DATA_ROLE));
+
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.MAPPED_ROLE, TYPE).set(ModelType.STRING);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.MAPPED_ROLE, REQUIRED).set(true);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.MAPPED_ROLE, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.MAPPED_ROLE));
+ }
+}
+
+class RemoveDataRole extends VDBOperations {
+
+ public RemoveDataRole() {
+ super("remove-data-role"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void executeOperation(OperationContext context, VDBService service, ModelNode operation) throws OperationFailedException {
+ if (!operation.hasDefined(OperationsConstants.DATA_ROLE)) {
+ throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.DATA_ROLE+MISSING)));
+ }
+
+ if (!operation.hasDefined(OperationsConstants.MAPPED_ROLE)) {
+ throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.MAPPED_ROLE+MISSING)));
+ }
+
+ String dataRole = operation.get(OperationsConstants.DATA_ROLE).asString();
+ String mappedRole = operation.get(OperationsConstants.MAPPED_ROLE).asString();
+
+ try {
+ service.addDataRole(dataRole, mappedRole);
+ } catch (AdminProcessingException e) {
+ throw new OperationFailedException(new ModelNode().set(e.getMessage()));
+ }
+ }
+
+ @Override
+ protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
+ super.describeParameters(operationNode, bundle);
+
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.DATA_ROLE, TYPE).set(ModelType.STRING);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.DATA_ROLE, REQUIRED).set(true);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.DATA_ROLE, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.DATA_ROLE));
+
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.MAPPED_ROLE, TYPE).set(ModelType.STRING);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.MAPPED_ROLE, REQUIRED).set(true);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.MAPPED_ROLE, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.MAPPED_ROLE));
+ }
+}
+
+class AddAnyAuthenticatedDataRole extends VDBOperations {
+
+ public AddAnyAuthenticatedDataRole() {
+ super("add-anyauthenticated-role"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void executeOperation(OperationContext context, VDBService service, ModelNode operation) throws OperationFailedException {
+ if (!operation.hasDefined(OperationsConstants.DATA_ROLE)) {
+ throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.DATA_ROLE+MISSING)));
+ }
+
+ String dataRole = operation.get(OperationsConstants.DATA_ROLE).asString();
+
+ try {
+ service.addAnyAuthenticated(dataRole);
+ } catch (AdminProcessingException e) {
+ throw new OperationFailedException(new ModelNode().set(e.getMessage()));
+ }
+ }
+
+ @Override
+ protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
+ super.describeParameters(operationNode, bundle);
+
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.DATA_ROLE, TYPE).set(ModelType.STRING);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.DATA_ROLE, REQUIRED).set(true);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.DATA_ROLE, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.DATA_ROLE));
+ }
+
+}
+
+class RemoveAnyAuthenticatedDataRole extends VDBOperations {
+
+ public RemoveAnyAuthenticatedDataRole() {
+ super("remove-anyauthenticated-role"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void executeOperation(OperationContext context, VDBService service, ModelNode operation) throws OperationFailedException {
+ if (!operation.hasDefined(OperationsConstants.DATA_ROLE)) {
+ throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.DATA_ROLE+MISSING)));
+ }
+
+ String dataRole = operation.get(OperationsConstants.DATA_ROLE).asString();
+
+ try {
+ service.removeAnyAuthenticated(dataRole);
+ } catch (AdminProcessingException e) {
+ throw new OperationFailedException(new ModelNode().set(e.getMessage()));
+ }
+ }
+
+ @Override
+ protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
+ super.describeParameters(operationNode, bundle);
+
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.DATA_ROLE, TYPE).set(ModelType.STRING);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.DATA_ROLE, REQUIRED).set(true);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.DATA_ROLE, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.DATA_ROLE));
+ }
+}
+
+class ChangeVDBConnectionType extends VDBOperations {
+
+ public ChangeVDBConnectionType() {
+ super("change-vdb-connection-type"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void executeOperation(OperationContext context, VDBService service, ModelNode operation) throws OperationFailedException {
+ if (!operation.hasDefined(OperationsConstants.CONNECTION_TYPE)) {
+ throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.CONNECTION_TYPE+MISSING)));
+ }
+
+ String connectionType = operation.get(OperationsConstants.CONNECTION_TYPE).asString();
+ try {
+ service.changeConnectionType(VDB.ConnectionType.valueOf(connectionType));
+ } catch (AdminProcessingException e) {
+ throw new OperationFailedException(new ModelNode().set(e.getMessage()));
+ }
+ }
+
+ @Override
+ protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
+ super.describeParameters(operationNode, bundle);
+
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.CONNECTION_TYPE, TYPE).set(ModelType.STRING);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.CONNECTION_TYPE, REQUIRED).set(true);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.CONNECTION_TYPE, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.CONNECTION_TYPE));
+ }
+}
+
+class AssignDataSource extends VDBOperations {
+
+ public AssignDataSource() {
+ super("assign-datasource"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void executeOperation(OperationContext context, VDBService service, ModelNode operation) throws OperationFailedException {
+ if (!operation.hasDefined(OperationsConstants.MODEL_NAME)) {
+ throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.MODEL_NAME+MISSING)));
+ }
+
+ if (!operation.hasDefined(OperationsConstants.SOURCE_NAME)) {
+ throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.SOURCE_NAME+MISSING)));
+ }
+
if (!operation.hasDefined(OperationsConstants.TRANSLATOR_NAME)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.TRANSLATOR_NAME+MISSING)));
}
+
+ if (!operation.hasDefined(OperationsConstants.DS_NAME)) {
+ throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.DS_NAME+MISSING)));
+ }
+
+ String modelName = operation.get(OperationsConstants.MODEL_NAME).asString();
+ String sourceName = operation.get(OperationsConstants.SOURCE_NAME).asString();
String translatorName = operation.get(OperationsConstants.TRANSLATOR_NAME).asString();
+ String dsName = operation.get(OperationsConstants.DS_NAME).asString();
- VDBTranslatorMetaData translator = repo.getTranslatorMetaData(translatorName);
- MetadataMapper.VDBTranslatorMetaDataMapper.wrap(translator, node);
+ try {
+ service.assignDatasource(modelName, sourceName, translatorName, dsName);
+ } catch (AdminProcessingException e) {
+ throw new OperationFailedException(new ModelNode().set(e.getMessage()));
+ }
}
+ @Override
protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
+ super.describeParameters(operationNode, bundle);
+
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.MODEL_NAME, TYPE).set(ModelType.STRING);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.MODEL_NAME, REQUIRED).set(true);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.MODEL_NAME, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.MODEL_NAME));
+
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.SOURCE_NAME, TYPE).set(ModelType.STRING);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.SOURCE_NAME, REQUIRED).set(true);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.SOURCE_NAME, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.MODEL_NAME));
+
operationNode.get(REQUEST_PROPERTIES, OperationsConstants.TRANSLATOR_NAME, TYPE).set(ModelType.STRING);
operationNode.get(REQUEST_PROPERTIES, OperationsConstants.TRANSLATOR_NAME, REQUIRED).set(true);
operationNode.get(REQUEST_PROPERTIES, OperationsConstants.TRANSLATOR_NAME, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.TRANSLATOR_NAME));
+
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.DS_NAME, TYPE).set(ModelType.STRING);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.DS_NAME, REQUIRED).set(true);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.DS_NAME, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.DS_NAME));
- operationNode.get(REPLY_PROPERTIES).set(VDBTranslatorMetaDataMapper.describe(new ModelNode()));
- operationNode.get(REPLY_PROPERTIES, DESCRIPTION).set(bundle.getString(getReplyName()));
- }
+ }
}
\ No newline at end of file
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/QueryEngineRemove.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/QueryEngineRemove.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/QueryEngineRemove.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -72,7 +72,7 @@
final ResourceBundle bundle = IntegrationPlugin.getResourceBundle(locale);
final ModelNode operation = new ModelNode();
operation.get(OPERATION_NAME).set(REMOVE);
- operation.get(DESCRIPTION).set(bundle.getString(REMOVE+DESCRIBE));
+ operation.get(DESCRIPTION).set(bundle.getString(REMOVE+"."+DESCRIBE)); //$NON-NLS-1$
return operation;
}
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidBootServicesAdd.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidBootServicesAdd.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidBootServicesAdd.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -77,11 +77,11 @@
static void describeTeiidRoot(final ResourceBundle bundle, String type, final ModelNode node) {
addAttribute(node, Configuration.ALLOW_ENV_FUNCTION, type, bundle.getString(Configuration.ALLOW_ENV_FUNCTION+DESC), ModelType.BOOLEAN, false, "false"); //$NON-NLS-1$
- addAttribute(node, Configuration.ASYNC_THREAD_GROUP, type, bundle.getString(Configuration.ASYNC_THREAD_GROUP+DESC), ModelType.STRING, true, "teiid-async-threads"); //$NON-NLS-1$
+ addAttribute(node, Configuration.ASYNC_THREAD_GROUP, type, bundle.getString(Configuration.ASYNC_THREAD_GROUP+DESC), ModelType.STRING, true, null);
- addAttribute(node, Configuration.AUTHORIZATION_VALIDATOR_MODULE, type, bundle.getString(Configuration.AUTHORIZATION_VALIDATOR_MODULE+DESC), ModelType.BOOLEAN, false, "false"); //$NON-NLS-1$
- addAttribute(node, Configuration.POLICY_DECIDER_MODULE, type, bundle.getString(Configuration.POLICY_DECIDER_MODULE+DESC), ModelType.STRING, false, "teiid-async-threads"); //$NON-NLS-1$
- addAttribute(node, Configuration.OBJECT_REPLICATOR, type, bundle.getString(Configuration.OBJECT_REPLICATOR+DESC), ModelType.STRING, false, "teiid/event-distributor"); //$NON-NLS-1$
+ addAttribute(node, Configuration.AUTHORIZATION_VALIDATOR_MODULE, type, bundle.getString(Configuration.AUTHORIZATION_VALIDATOR_MODULE+DESC), ModelType.BOOLEAN, false, null);
+ addAttribute(node, Configuration.POLICY_DECIDER_MODULE, type, bundle.getString(Configuration.POLICY_DECIDER_MODULE+DESC), ModelType.STRING, false, null);
+ addAttribute(node, Configuration.OBJECT_REPLICATOR, type, bundle.getString(Configuration.OBJECT_REPLICATOR+DESC), ModelType.STRING, false, null);
ModelNode bufferNode = node.get(CHILDREN, Configuration.BUFFER_SERVICE);
bufferNode.get(TYPE).set(ModelType.OBJECT);
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidExtension.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidExtension.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidExtension.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -109,23 +109,26 @@
// teiid level admin api operation handlers
new GetTranslator().register(teiidSubsystem);
- new GetTranslators().register(teiidSubsystem);
+ new ListTranslators().register(teiidSubsystem);
new MergeVDBs().register(teiidSubsystem);
new ListVDBs().register(teiidSubsystem);
new GetVDB().register(teiidSubsystem);
+ new CacheTypes().register(teiidSubsystem);
+ new ClearCache().register(teiidSubsystem);
+ new CacheStatistics().register(teiidSubsystem);
+ new AddDataRole().register(teiidSubsystem);
+ new RemoveDataRole().register(teiidSubsystem);
+ new AddAnyAuthenticatedDataRole().register(teiidSubsystem);
// engine level admin api handlers
- new GetActiveSessions().register(engineSubsystem);
- new GetRequestsPerSession().register(engineSubsystem);
- new GetRequestsPerVDB().register(engineSubsystem);
+ new ListSessions().register(engineSubsystem);
+ new RequestsPerSession().register(engineSubsystem);
+ new RequestsPerVDB().register(engineSubsystem);
new GetLongRunningQueries().register(engineSubsystem);
new TerminateSession().register(engineSubsystem);
- new CancelQuery().register(engineSubsystem);
- new CacheTypes().register(engineSubsystem);
- new ClearCache().register(engineSubsystem);
- new CacheStatistics().register(engineSubsystem);
+ new CancelRequest().register(engineSubsystem);
new WorkerPoolStatistics().register(engineSubsystem);
- new ActiveTransactions().register(engineSubsystem);
+ new ListTransactions().register(engineSubsystem);
new TerminateTransaction().register(engineSubsystem);
new ExecuteQuery().register(engineSubsystem);
}
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -29,11 +29,11 @@
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
-import org.jboss.msc.service.*;
+import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceBuilder.DependencyType;
+import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceController.Mode;
import org.teiid.adminapi.Translator;
-import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.adminapi.impl.VDBTranslatorMetaData;
import org.teiid.deployers.TeiidAttachments;
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/VDBParserDeployer.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/VDBParserDeployer.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/VDBParserDeployer.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -21,12 +21,14 @@
*/
package org.teiid.jboss;
+import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.server.deployment.*;
+import org.jboss.msc.service.ServiceController;
import org.jboss.vfs.VirtualFile;
import org.teiid.adminapi.Model;
import org.teiid.adminapi.impl.ModelMetaData;
@@ -56,31 +58,31 @@
}
VirtualFile file = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
-
+
if (TeiidAttachments.isDynamicVDB(deploymentUnit)) {
- parseVDBXML(file, deploymentUnit).setDynamic(true);
+ parseVDBXML(file, deploymentUnit, phaseContext).setDynamic(true);
}
else {
// scan for different files
List<VirtualFile> childFiles = file.getChildren();
for (VirtualFile childFile:childFiles) {
- scanVDB(childFile, deploymentUnit);
+ scanVDB(childFile, deploymentUnit, phaseContext);
}
mergeMetaData(deploymentUnit);
}
}
- private void scanVDB(VirtualFile file, DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
+ private void scanVDB(VirtualFile file, DeploymentUnit deploymentUnit, DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
if (file.isDirectory()) {
List<VirtualFile> childFiles = file.getChildren();
for (VirtualFile childFile:childFiles) {
- scanVDB(childFile, deploymentUnit);
+ scanVDB(childFile, deploymentUnit, phaseContext);
}
}
else {
if (file.getName().toLowerCase().equals(VdbConstants.DEPLOYMENT_FILE)) {
- parseVDBXML(file, deploymentUnit);
+ parseVDBXML(file, deploymentUnit, phaseContext);
}
else if (file.getName().endsWith(VdbConstants.INDEX_EXT)) {
IndexMetadataFactory imf = deploymentUnit.getAttachment(TeiidAttachments.INDEX_METADATA);
@@ -101,9 +103,14 @@
}
}
- private VDBMetaData parseVDBXML(VirtualFile file, DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
+ private VDBMetaData parseVDBXML(VirtualFile file, DeploymentUnit deploymentUnit, DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
try {
VDBMetaData vdb = VDBMetadataParser.unmarshell(file.openStream());
+ ServiceController<?> sc = phaseContext.getServiceRegistry().getService(TeiidServiceNames.OBJECT_SERIALIZER);
+ ObjectSerializer serializer = ObjectSerializer.class.cast(sc.getValue());
+ if (serializer.buildVdbXml(vdb).exists()) {
+ vdb = VDBMetadataParser.unmarshell(new FileInputStream(serializer.buildVdbXml(vdb)));
+ }
deploymentUnit.putAttachment(TeiidAttachments.VDB_METADATA, vdb);
LogManager.logDetail(LogConstants.CTX_RUNTIME,"VDB "+file.getName()+" has been parsed."); //$NON-NLS-1$ //$NON-NLS-2$
return vdb;
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -27,18 +27,16 @@
import java.util.*;
import java.util.concurrent.Executor;
+import javax.xml.stream.XMLStreamException;
+
import org.jboss.msc.service.Service;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.jboss.msc.value.InjectedValue;
-import org.teiid.adminapi.Model;
-import org.teiid.adminapi.Translator;
-import org.teiid.adminapi.VDB;
-import org.teiid.adminapi.impl.ModelMetaData;
-import org.teiid.adminapi.impl.SourceMappingMetadata;
-import org.teiid.adminapi.impl.VDBMetaData;
-import org.teiid.adminapi.impl.VDBTranslatorMetaData;
+import org.teiid.adminapi.*;
+import org.teiid.adminapi.VDB.ConnectionType;
+import org.teiid.adminapi.impl.*;
import org.teiid.common.buffer.BufferManager;
import org.teiid.core.TeiidException;
import org.teiid.deployers.*;
@@ -457,4 +455,80 @@
public void undeployInProgress() {
this.undeployInProgress = true;
}
+
+ public void addDataRole(String policyName, String mappedRole) throws AdminProcessingException{
+ DataPolicyMetadata policy = vdb.getDataPolicy(policyName);
+
+ if (policy == null) {
+ throw new AdminProcessingException(IntegrationPlugin.Util.getString("policy_not_found", policyName, this.vdb.getName(), this.vdb.getVersion())); //$NON-NLS-1$
+ }
+
+ policy.addMappedRoleName(mappedRole);
+ save();
+ }
+
+ public void remoteDataRole(String policyName, String mappedRole) throws AdminProcessingException{
+ DataPolicyMetadata policy = vdb.getDataPolicy(policyName);
+
+ if (policy == null) {
+ throw new AdminProcessingException(IntegrationPlugin.Util.getString("policy_not_found", policyName, this.vdb.getName(), this.vdb.getVersion())); //$NON-NLS-1$
+ }
+
+ policy.removeMappedRoleName(mappedRole);
+ save();
+ }
+
+ public void addAnyAuthenticated(String policyName) throws AdminProcessingException{
+ DataPolicyMetadata policy = vdb.getDataPolicy(policyName);
+
+ if (policy == null) {
+ throw new AdminProcessingException(IntegrationPlugin.Util.getString("policy_not_found", policyName, this.vdb.getName(), this.vdb.getVersion())); //$NON-NLS-1$
+ }
+
+ policy.setAnyAuthenticated(true);
+ save();
+ }
+
+ public void removeAnyAuthenticated(String policyName) throws AdminProcessingException{
+ DataPolicyMetadata policy = vdb.getDataPolicy(policyName);
+
+ if (policy == null) {
+ throw new AdminProcessingException(IntegrationPlugin.Util.getString("policy_not_found", policyName, this.vdb.getName(), this.vdb.getVersion())); //$NON-NLS-1$
+ }
+
+ policy.setAnyAuthenticated(false);
+ save();
+ }
+
+ public void changeConnectionType(ConnectionType type) throws AdminProcessingException {
+ this.vdb.setConnectionType(type);
+ save();
+ }
+
+ public void assignDatasource(String modelName, String sourceName, String translatorName, String dsName) throws AdminProcessingException{
+ ModelMetaData model = this.vdb.getModel(modelName);
+
+ if (model == null) {
+ throw new AdminProcessingException(IntegrationPlugin.Util.getString("model_not_found", modelName, this.vdb.getName(), this.vdb.getVersion())); //$NON-NLS-1$
+ }
+
+ SourceMappingMetadata source = model.getSourceMapping(sourceName);
+ if(source == null) {
+ throw new AdminProcessingException(IntegrationPlugin.Util.getString("source_not_found", sourceName, modelName, this.vdb.getName(), this.vdb.getVersion())); //$NON-NLS-1$
+ }
+ source.setTranslatorName(translatorName);
+ source.setConnectionJndiName(dsName);
+ save();
+ }
+
+ private void save() throws AdminProcessingException{
+ try {
+ ObjectSerializer os = getSerializer();
+ VDBMetadataParser.marshell(this.vdb, os.getVdbXmlOutputStream(this.vdb));
+ } catch (IOException e) {
+ throw new AdminProcessingException(e);
+ } catch (XMLStreamException e) {
+ throw new AdminProcessingException(e);
+ }
+ }
}
Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -46,7 +46,6 @@
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StopContext;
import org.jboss.msc.value.InjectedValue;
-import org.teiid.adminapi.Admin.Cache;
import org.teiid.adminapi.AdminComponentException;
import org.teiid.adminapi.AdminException;
import org.teiid.adminapi.AdminProcessingException;
@@ -261,8 +260,8 @@
}
// dump the caches.
- dqpCore.clearCache(Cache.PREPARED_PLAN_CACHE.toString(), name, version);
- dqpCore.clearCache(Cache.QUERY_SERVICE_RESULT_SET_CACHE.toString(), name, version);
+ getResultSetCacheInjector().getValue().clearForVDB(name, version);
+ getPreparedPlanCacheInjector().getValue().clearForVDB(name, version);
}
});
}
@@ -399,26 +398,6 @@
}
@Override
- public Collection<String> getCacheTypes(){
- return this.dqpCore.getCacheTypes();
- }
-
- @Override
- public void clearCache(String cacheType) {
- this.dqpCore.clearCache(cacheType);
- }
-
- @Override
- public void clearCache(String cacheType, String vdbName, int version) {
- this.dqpCore.clearCache(cacheType, vdbName, version);
- }
-
- @Override
- public CacheStatisticsMetadata getCacheStatistics(String cacheType) {
- return this.dqpCore.getCacheStatistics(cacheType);
- }
-
- @Override
public Collection<SessionMetadata> getActiveSessions() throws AdminException {
try {
return this.sessionService.getActiveSessions();
@@ -779,5 +758,5 @@
public InjectedValue<ObjectReplicator> getObjectReplicatorInjector() {
return objectReplicatorInjector;
- }
+ }
}
Modified: branches/as7/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties
===================================================================
--- branches/as7/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties 2011-09-23 04:11:11 UTC (rev 3503)
@@ -29,6 +29,7 @@
bad_vdb_extension=The extension of the file name must be either ".vdb" for designer vdb or "xxx-vdb.xml" for dynamic VDBs
vdb_not_found=VDB with name "{0}" version "{1}" not found in configuration
model_not_found=Model name "{0}" not found in the VDB with name "{1}" version "{2}"
+model_not_found=Source name "{0}" not found in model {1} in the VDB with name "{2}" version "{3}"
policy_not_found=Policy name "{0}" not found in the VDB with name "{1}" version "{2}"
datasource_not_found=Datasource {0} not found in the configuration.
sourcename_not_found=No source name {0} found in the model: {1}.{2}.{3}
@@ -59,6 +60,7 @@
translator.added = Teiid translator "{0}" added.
# subsystem description
+susbsystem.add = Add the Teiid Subsystem
buffer-service.describe=Buffer Manager Configuration
resultset-cache.describe=Configuration for result set caching. There will be 2 caches with these settings. One cache holds results that are specific to sessions. The other cache holds vdb scoped results and can be replicated
preparedplan-cache.describe=PreparedPlan Cache Configuration
@@ -142,53 +144,7 @@
truststore-password.describe=Truststore Password
authentication-mode.describe=Authentication Mode (1-way, 2-way, anonymous)
ssl.describe=SSL
-
-
-
-# Add
-susbsystem.add = Add the Teiid Subsystem
-
-#engine managed operations
-active-sessions.describe=List of all the current active sessions in the Teiid subsystem.
-requests-per-session.describe=Current active requests in progress in the query engine for a given session identifier
-requests-per-session.session.describe=The session Identifier
-requests-per-vdb.describe=Current active requests in progress in the query engine for a given VDB name and its version.
-requests-per-vdb.vdb_name.describe=VDB Name
-requests-per-vdb.vdb_version.describe=VDB Version
-long-running-queries.describe=Long running queries that exceeded the threshold set by the 'queryThresholdInSecs' configuration property.
-terminate-session.describe=Terminate the session
-terminate-session.session.describe=The session Identifier of session to be terminated
-cancel-query.describe=Cancel the execution of the actively running query
-cancel-query.session.describe=The session Identifier of the user
-cancel-query.execution-id.describe=The Execution Identifier of the query
-cache-types.describe=List the available cache types
-
-clear-cache.describe=Clear the caches in the system of the given type
-clear-cache.cache-type.describe=cache type to be cleared. (PREPARED_PLAN_CACHE, QUERY_SERVICE_RESULT_SET_CACHE)
-clear-cache.vdb-name.describe=VDB name
-clear-cache.vdb_version.describe=VDB version
-cache-statistics.describe=Get the cache statistics for the given cache type
-cache-statistics.cache-type.describe=cache type (PREPARED_PLAN_CACHE, QUERY_SERVICE_RESULT_SET_CACHE)
-
-workerpool-statistics.describe=Get thread statistics worker pool
-active-transactions.describe=Active Transactions in the Query Engine
-
-terminate-transaction.describe=Terminate the XA transaction
-terminate-transaction.xid.describe=xid identifier of the XA transaction
-merge-vdbs.describe=Merge Two VDBs
-merge-vdbs.source-vdb-name.describe=Source VDB name
-merge-vdbs.source-vdb-version.describe=Source VDB version number
-merge-vdbs.target-vdb-name.describe=Target VDB name
-merge-vdbs.target-vdb-version.describe=Target VDB version number
-
-execute-query.describe=Execute a sql query
-execute-query.vdb-name.describe=vdb name
-execute-query.vdb-version.describe=vdb version
-execute-query.sql-query.describe=sql query to execute
-execute-query.timeout-in-milli.describe=timeout
-
socket-binding.not_defined=Teiid socket binding not defined for JDBC or ODBC port.
-
name.describe = Name of the subsystem
module.describe = Name of the implementing module
engine.remove = Remove Teiid query engine
@@ -202,22 +158,22 @@
hit-ratio.describe = Cache Hit ratio
request-count.describe=Total request count
-cache-types.cache-type.describe=cache type
-get-translators.reply.describe=Returns list of translators registered in the teiid container
-get-translator.reply.describe=Returns translator if found with given name
-active-session-count.reply.describe=Returns the count of active sessions
-runtime-version.reply.describe=Teiid runtime version
-list-vdbs.describe=List the available virtual databases in the system
-cancel-query.reply.describe=True if successful; false otherwise.
-clear-cache.vdb-version.describe=vdb version
-get-vdb.describe=Get the VDB with the given name and version
-get-vdb.vdb-name.describe=name of the vdb
-get-vdb.vdb-version.describe=vdb version
-requests-per-vdb.vdb-name.describe=vdb name
-requests-per-vdb.vdb-version.describe=vdb version
+engine_service_not_found= Query Engine Service with name {0} is not found
+translator.removed = Translator "{0}" removed
+translator.failed-to-load = Translator "{0}" not found in the module "{1}"
+cache-container-name-required=container-name required for the resultset cache configuration
+object-replicator.describe=Object Replication
+enable.describe=enabled
+
+clearing_cache=Clearing cache {0} for all the deployed vdbs.
+clearing_cache_vdb=Clearing cache {0} for vdb {1}.{2}
+vdb-inactive=VDB {0}.{1} deployed in inactive state due to unavailability of data sources {2}
+
+
remove.reply.describe=remove service
remove.describe=remove service
+# paramters missing
vdb-name.missing=Parameter "vdb-name" is required
vdb-version.missing=Parameter "vdb-version" is required
cache-type.missing=Parameter "cache-type" is required
@@ -231,10 +187,118 @@
sql-query.missing=Parameter "sql-query" is required
timeout-in-milli.missing=Parameter "timeout-in-milli" is required
translator-name.missing=Parameter "translator-name" is required
-engine_service_not_found= Query Engine Service with name {0} is not found
-translator.removed = Translator "{0}" removed
-translator.failed-to-load = Translator "{0}" not found in the module "{1}"
-cache-container-name-required=container-name required for the resultset cache configuration
+data-role.missing = Data Role is missing from parameters
+mapped-role.missing = security domain role is missing from parameters
+source-name.missing=Model source name is required
+ds-name.missing=Data source name required
+translator-name.missing=translator name required
+model-name.missing=Model Name required
+connection-type.missing = VDB connection type is required
-vdb-inactive=VDB {0}.{1} deployed in inactive state due to unavailability of data sources {2}
\ No newline at end of file
+
+
+# Operation descriptions (alpha layout)
+add-anyauthenticated-role.describe=Mark any authenticated to the datarole
+add-anyauthenticated-role.vdb-name.describe=VDB Name
+add-anyauthenticated-role.vdb-version.describe=VDB Version
+add-anyauthenticated-role.data-role.describe=VDB Defined Data Role Name
+
+add-data-role.describe= Map a JAAS based role to the VDB data role, for granting permission
+add-data-role.vdb-name.describe=VDB Name
+add-data-role.vdb-version.describe=VDB Version
+add-data-role.data-role.describe=VDB Defined Data Role Name
+add-data-role.mapped-role.describe=Security domain defined role name
+
+assign-datasource.describe=Assign a data source or translator names to a given model in the VDB
+assign-datasource.vdb-name.describe=VDB Name
+assign-datasource.vdb-version.describe=VDB Version
+assign-datasource.source-name.describe=Model Source Name
+assign-datasource.ds-name.describe=Data source name
+assign-datasource.translator-name.describe=translator name
+assign-datasource.model-name.describe=Model Name
+
+cache-statistics.describe=Get the cache statistics for the given cache type
+cache-statistics.cache-type.describe=cache type (PREPARED_PLAN_CACHE, QUERY_SERVICE_RESULT_SET_CACHE)
+
+cache-types.describe=List the available cache types
+
+cancel-request.describe=Cancel the execution of the actively running query
+cancel-request.session.describe=The session Identifier of the user
+cancel-request.execution-id.describe=The Execution Identifier of the query
+cancel-request.reply.describe=True if successful; false otherwise.
+
+change-vdb-connection-type.describe=Change the default VDB version selection
+change-vdb-connection-type.vdb-name.describe=VDB Name
+change-vdb-connection-type.vdb-version.describe=VDB Version
+change-vdb-connection-type.connection-type.describe=VDB Connection Type
+
+clear-cache.describe=Clear the caches in the system of the given type
+clear-cache.cache-type.describe=cache type to be cleared. (PREPARED_PLAN_CACHE, QUERY_SERVICE_RESULT_SET_CACHE)
+clear-cache.vdb-name.describe=VDB name
+clear-cache.vdb_version.describe=VDB version
+
+execute-query.describe=Execute a sql query
+execute-query.vdb-name.describe=vdb name
+execute-query.vdb-version.describe=vdb version
+execute-query.sql-query.describe=sql query to execute
+execute-query.timeout-in-milli.describe=timeout
+
+active-session-count.describe=Number of active sessions
+active-session-count.reply.describe=Returns the count of active sessions
+
+long-running-queries.describe=Long running queries that exceeded the threshold set by the 'query-threshold-in-seconds' configuration property.
+
+runtime-version.describe = Runtime version of the Teiid subsystem
+runtime-version.reply.describe=Teiid runtime version
+
+get-translator.describe=retrieve translator
+get-translator.translator-name.describe=translator name
+get-translator.reply.describe=Returns translator if found with given name
+
+get-vdb.describe=Get the VDB with the given name and version
+get-vdb.vdb-name.describe=name of the vdb
+get-vdb.vdb-version.describe=vdb version
+
+list-requests.describe=List of active requests
+
+list-sessions.describe=List of all the current active sessions in the Teiid subsystem.
+
+list-transactions.describe=Active Transactions in the Query Engine
+
+list-translators.describe=List of translators registered in the teiid container
+list-translators.reply.describe=List of translators registered in the teiid container
+
+list-vdbs.describe=List the available virtual databases in the system
+
+merge-vdbs.describe=Merge Two VDBs
+merge-vdbs.source-vdb-name.describe=Source VDB name
+merge-vdbs.source-vdb-version.describe=Source VDB version number
+merge-vdbs.target-vdb-name.describe=Target VDB name
+merge-vdbs.target-vdb-version.describe=Target VDB version number
+
+remove-anyauthenticated-role.describe=remove any authenticated from the data role provided
+remove-anyauthenticated-role.vdb-name.describe=VDB Name
+remove-anyauthenticated-role.vdb-version.describe=VDB Version
+remove-anyauthenticated-role.data-role.describe=VDB Defined Data Role Name
+
+remove-data-role.describe=remove the JAAS based role mapping from VDB data role
+remove-data-role.vdb-name.describe=VDB Name
+remove-data-role.vdb-version.describe=VDB Version
+remove-data-role.data-role.describe=VDB Defined Data Role Name
+remove-data-role.mapped-role.describe=Security domain defined role name
+
+requests-per-session.describe=Current active requests in progress in the query engine for a given session identifier
+requests-per-session.session.describe=The session Identifier
+
+requests-per-vdb.describe=Current active requests in progress in the query engine for a given VDB name and its version.
+requests-per-vdb.vdb_name.describe=VDB Name
+requests-per-vdb.vdb_version.describe=VDB Version
+
+terminate-session.describe=Terminate the session
+terminate-session.session.describe=The session Identifier of session to be terminated
+
+terminate-transaction.describe=Terminate the XA transaction
+terminate-transaction.xid.describe=xid identifier of the XA transaction
+
+workerpool-statistics.describe=Get thread statistics worker pool
\ No newline at end of file
Modified: branches/as7/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestAdminObjectBuilder.java
===================================================================
--- branches/as7/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestAdminObjectBuilder.java 2011-09-21 04:13:59 UTC (rev 3502)
+++ branches/as7/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestAdminObjectBuilder.java 2011-09-23 04:11:11 UTC (rev 3503)
@@ -97,8 +97,8 @@
vdb.addDataPolicy(roleOne);
// convert to managed object and build the VDB out of MO
- ModelNode node = MetadataMapper.wrap(vdb, new ModelNode());
- vdb = MetadataMapper.unwrap(node);
+ ModelNode node = VDBMetadataMapper.INSTANCE.wrap(vdb, new ModelNode());
+ vdb = VDBMetadataMapper.INSTANCE.unwrap(node);
assertEquals("myVDB", vdb.getName());
assertEquals("vdb description", vdb.getDescription());
@@ -169,8 +169,8 @@
tm.addProperty("ExtensionTranslationClassName", "org.teiid.translator.jdbc.oracle.OracleSQLTranslator");
// convert to managed object and build the VDB out of MO
- ModelNode node = MetadataMapper.VDBTranslatorMetaDataMapper.wrap(tm, new ModelNode());
- VDBTranslatorMetaData tm1 = MetadataMapper.VDBTranslatorMetaDataMapper.unwrap(node);
+ ModelNode node = VDBMetadataMapper.VDBTranslatorMetaDataMapper.INSTANCE.wrap(tm, new ModelNode());
+ VDBTranslatorMetaData tm1 = VDBMetadataMapper.VDBTranslatorMetaDataMapper.INSTANCE.unwrap(node);
assertEquals("Oracle", tm1.getName());
assertEquals(ExecutionFactory.class.getName(), tm1.getPropertyValue(Translator.EXECUTION_FACTORY_CLASS));
[View Less]
13 years, 6 months
teiid SVN: r3502 - in trunk: client/src/main/java/org/teiid/client and 20 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-09-21 00:13:59 -0400 (Wed, 21 Sep 2011)
New Revision: 3502
Added:
trunk/engine/src/main/java/org/teiid/common/buffer/AutoCleanupUtil.java
trunk/engine/src/main/java/org/teiid/common/buffer/Cache.java
trunk/engine/src/main/java/org/teiid/common/buffer/CacheEntry.java
trunk/engine/src/main/java/org/teiid/common/buffer/LightWeightCopyOnWriteList.java
trunk/engine/src/main/java/org/teiid/common/buffer/Serializer.java
trunk/engine/src/main/java/org/…
[View More]teiid/common/buffer/impl/BitSetTree.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStoreCache.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/SerializableTupleBatch.java
trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBitSetTree.java
trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStoreCache.java
Removed:
trunk/engine/src/test/java/org/teiid/core/
Modified:
trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/TupleBatchCacheLoader.java
trunk/client/src/main/java/org/teiid/client/BatchSerializer.java
trunk/client/src/main/java/org/teiid/client/ResultsMessage.java
trunk/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java
trunk/client/src/test/java/org/teiid/client/TestBatchSerializer.java
trunk/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java
trunk/client/src/test/java/org/teiid/jdbc/TestCallableStatement.java
trunk/common-core/src/main/java/org/teiid/core/types/DataTypeManager.java
trunk/engine/src/main/java/org/teiid/common/buffer/BatchManager.java
trunk/engine/src/main/java/org/teiid/common/buffer/FileStore.java
trunk/engine/src/main/java/org/teiid/common/buffer/FileStoreInputStreamFactory.java
trunk/engine/src/main/java/org/teiid/common/buffer/LobManager.java
trunk/engine/src/main/java/org/teiid/common/buffer/SPage.java
trunk/engine/src/main/java/org/teiid/common/buffer/STree.java
trunk/engine/src/main/java/org/teiid/common/buffer/TupleBatch.java
trunk/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java
trunk/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStorageManager.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/MemoryStorageManager.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/SizeUtility.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
trunk/engine/src/main/java/org/teiid/dqp/message/AtomicResultsMessage.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/EnhancedSortMergeJoinStrategy.java
trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java
trunk/engine/src/test/java/org/teiid/common/buffer/BufferManagerFactory.java
trunk/engine/src/test/java/org/teiid/common/buffer/TestLobManager.java
trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java
trunk/engine/src/test/java/org/teiid/common/buffer/TestTupleBuffer.java
trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStorageManager.java
trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestSizeUtility.java
trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestSplittableStorageManager.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestCachedResults.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
trunk/engine/src/test/java/org/teiid/dqp/service/AutoGenDataService.java
trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
trunk/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java
trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestElementSymbol.java
trunk/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java
trunk/runtime/src/test/java/org/teiid/dqp/service/buffer/TestLocalBufferService.java
Log:
TEIID-1750 fixed update leaking with transactional temp tables. switching the buffermanager caching logic to focus solely on memory management. minimized the memory footprint of the buffermanager and managed batches. switching the disk cache logic to a block approach - which will also allow for the introduction of off-heap caching. adding a batched mode for ordered temp table inserts.
Modified: trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/TupleBatchCacheLoader.java
===================================================================
--- trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/TupleBatchCacheLoader.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/TupleBatchCacheLoader.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -31,6 +31,7 @@
import org.teiid.common.buffer.TupleBatch;
import org.teiid.common.buffer.TupleBuffer;
import org.teiid.core.TeiidRuntimeException;
+import org.teiid.dqp.internal.process.SerializableTupleBatch;
public class TupleBatchCacheLoader extends ClusteredTupleBatchCacheLoader {
@@ -58,8 +59,7 @@
if (tb != null) {
Map map = new HashMap();
TupleBatch b = tb.getBatch(row);
- b.preserveTypes();
- map.put(id, b);
+ map.put(id, new SerializableTupleBatch(b, tb.getTypes()));
return map;
}
}
Modified: trunk/client/src/main/java/org/teiid/client/BatchSerializer.java
===================================================================
--- trunk/client/src/main/java/org/teiid/client/BatchSerializer.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/client/src/main/java/org/teiid/client/BatchSerializer.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -29,6 +29,7 @@
import java.math.BigInteger;
import java.sql.Time;
import java.sql.Timestamp;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -75,23 +76,23 @@
* @throws IOException
* @since 4.2
*/
- static void writeIsNullData(ObjectOutput out, int col, List[] batch) throws IOException {
- int numBytes = batch.length / 8, row = 0, currentByte = 0;
+ static void writeIsNullData(ObjectOutput out, int col, List<? extends List<?>> batch) throws IOException {
+ int numBytes = batch.size() / 8, row = 0, currentByte = 0;
for (int byteNum = 0; byteNum < numBytes; byteNum++, row+=8) {
- currentByte = (batch[row].get(col) == null) ? 0x80 : 0;
- if (batch[row+1].get(col) == null) currentByte |= 0x40;
- if (batch[row+2].get(col) == null) currentByte |= 0x20;
- if (batch[row+3].get(col) == null) currentByte |= 0x10;
- if (batch[row+4].get(col) == null) currentByte |= 0x08;
- if (batch[row+5].get(col) == null) currentByte |= 0x04;
- if (batch[row+6].get(col) == null) currentByte |= 0x02;
- if (batch[row+7].get(col) == null) currentByte |= 0x01;
+ currentByte = (batch.get(row).get(col) == null) ? 0x80 : 0;
+ if (batch.get(row+1).get(col) == null) currentByte |= 0x40;
+ if (batch.get(row+2).get(col) == null) currentByte |= 0x20;
+ if (batch.get(row+3).get(col) == null) currentByte |= 0x10;
+ if (batch.get(row+4).get(col) == null) currentByte |= 0x08;
+ if (batch.get(row+5).get(col) == null) currentByte |= 0x04;
+ if (batch.get(row+6).get(col) == null) currentByte |= 0x02;
+ if (batch.get(row+7).get(col) == null) currentByte |= 0x01;
out.write(currentByte);
}
- if (batch.length % 8 > 0) {
+ if (batch.size() % 8 > 0) {
currentByte = 0;
- for (int mask = 0x80; row < batch.length; row++, mask >>= 1) {
- if (batch[row].get(col) == null) currentByte |= mask;
+ for (int mask = 0x80; row < batch.size(); row++, mask >>= 1) {
+ if (batch.get(row).get(col) == null) currentByte |= mask;
}
out.write(currentByte);
}
@@ -126,22 +127,22 @@
* @since 4.2
*/
private static class ColumnSerializer {
- public void writeColumn(ObjectOutput out, int col, List[] batch) throws IOException {
+ public void writeColumn(ObjectOutput out, int col, List<? extends List<?>> batch) throws IOException {
writeIsNullData(out, col, batch);
Object obj = null;
- for (int i = 0; i < batch.length; i++) {
- obj = batch[i].get(col);
+ for (int i = 0; i < batch.size(); i++) {
+ obj = batch.get(i).get(col);
if (obj != null) {
writeObject(out, obj);
}
}
}
- public void readColumn(ObjectInput in, int col, List[] batch, byte[] isNull) throws IOException, ClassNotFoundException {
+ public void readColumn(ObjectInput in, int col, List<List<Object>> batch, byte[] isNull) throws IOException, ClassNotFoundException {
readIsNullData(in, isNull);
- for (int i = 0; i < batch.length; i++) {
+ for (int i = 0; i < batch.size(); i++) {
if (!isNullObject(isNull, i)) {
- batch[i].set(col, DataTypeManager.getCanonicalValue(readObject(in)));
+ batch.get(i).set(col, DataTypeManager.getCanonicalValue(readObject(in)));
}
}
}
@@ -203,13 +204,14 @@
/* This implementation compacts the isNull and boolean data for non-null values into a byte[]
* by using a 8 bit mask that is bit-shifted to mask each value.
*/
- public void writeColumn(ObjectOutput out, int col, List[] batch) throws IOException {
+ @Override
+ public void writeColumn(ObjectOutput out, int col, List<? extends List<?>> batch) throws IOException {
int currentByte = 0;
int mask = 0x80;
Object obj;
- for (int row = 0; row < batch.length; row++) {
+ for (int row = 0; row < batch.size(); row++) {
// Write the isNull value
- obj = batch[row].get(col);
+ obj = batch.get(row).get(col);
if (obj == null ) {
currentByte |= mask;
}
@@ -241,10 +243,13 @@
}
}
- public void readColumn(ObjectInput in, int col, List[] batch, byte[] isNull) throws IOException, ClassNotFoundException {
+ @Override
+ public void readColumn(ObjectInput in, int col,
+ List<List<Object>> batch, byte[] isNull) throws IOException,
+ ClassNotFoundException {
int currentByte = 0, mask = 0; // Initialize the mask so that it is reset in the loop
boolean isNullVal;
- for (int row = 0; row < batch.length; row++) {
+ for (int row = 0; row < batch.size(); row++) {
if (mask == 0) {
// If we used up the byte, read the next one, and reset the mask
currentByte = in.read();
@@ -257,7 +262,7 @@
currentByte = in.read();
mask = 0x80;
}
- batch[row].set(col, ((currentByte & mask) == 0) ? Boolean.FALSE : Boolean.TRUE);
+ batch.get(row).set(col, ((currentByte & mask) == 0) ? Boolean.FALSE : Boolean.TRUE);
mask >>= 1;
}
}
@@ -354,17 +359,12 @@
return cs;
}
- public static void writeBatch(ObjectOutput out, String[] types, List[] batch) throws IOException {
- // If there are no type hints, simply use the default mechanism to serialize
- if (types == null || types.length == 0) {
- out.writeObject(batch);
- return;
- }
+ public static void writeBatch(ObjectOutput out, String[] types, List<? extends List<?>> batch) throws IOException {
if (batch == null) {
out.writeInt(-1);
} else {
- out.writeInt(batch.length);
- if (batch.length > 0) {
+ out.writeInt(batch.size());
+ if (batch.size() > 0) {
int columns = types.length;
out.writeInt(columns);
for(int i = 0; i < columns; i++) {
@@ -374,8 +374,8 @@
} catch (ClassCastException e) {
Object obj = null;
String objectClass = null;
- objectSearch: for (int row = 0; row < batch.length; row++) {
- obj = batch[row].get(i);
+ objectSearch: for (int row = 0; row < batch.size(); row++) {
+ obj = batch.get(row).get(i);
if (obj != null) {
objectClass = obj.getClass().getName();
break objectSearch;
@@ -388,21 +388,17 @@
}
}
- public static List[] readBatch(ObjectInput in, String[] types) throws IOException, ClassNotFoundException {
- // If there are no type hints, use the default mechanism to deserialize
- if (types == null || types.length == 0) {
- return (List[])in.readObject();
- }
+ public static List<List<Object>> readBatch(ObjectInput in, String[] types) throws IOException, ClassNotFoundException {
int rows = in.readInt();
if (rows == 0) {
- return new List[0];
+ return new ArrayList<List<Object>>(0);
} else if (rows > 0) {
int columns = in.readInt();
- List[] batch = new List[rows];
+ List<List<Object>> batch = new ArrayList<List<Object>>(rows);
int numBytes = rows/8;
int extraRows = rows % 8;
for (int currentRow = 0; currentRow < rows; currentRow++) {
- batch[currentRow] = Arrays.asList(new Object[columns]);
+ batch.add(currentRow, Arrays.asList(new Object[columns]));
}
byte[] isNullBuffer = new byte[(extraRows > 0) ? numBytes + 1: numBytes];
for (int col = 0; col < columns; col++) {
Modified: trunk/client/src/main/java/org/teiid/client/ResultsMessage.java
===================================================================
--- trunk/client/src/main/java/org/teiid/client/ResultsMessage.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/client/src/main/java/org/teiid/client/ResultsMessage.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -26,7 +26,7 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
-import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -45,9 +45,9 @@
static final long serialVersionUID = 3546924172976187793L;
- private List[] results = null;
- private String[] columnNames = null;
- private String[] dataTypes = null;
+ private List<? extends List<?>> results;
+ private String[] columnNames;
+ private String[] dataTypes;
/** A description of planning that occurred as requested in the request. */
private PlanNode planDescription;
@@ -85,36 +85,29 @@
public ResultsMessage(){
}
- /**
- * Instantiate and copy relevant information from the original request message.
- * Typically, the transaction context should only be copied if this results
- * message is being returned from the connector to the query engine. Clients
- * will be unable to deserialize this object.
- * @param requestMsg
- * @param copyTransactionContext true if the transaction context should be copied; false otherwise.
- * @since 4.2
- */
- public ResultsMessage(RequestMessage requestMsg){
- this.results = new ArrayList[0];
-
- }
-
- public ResultsMessage(RequestMessage requestMsg, List[] results, String[] columnNames, String[] dataTypes){
- this (requestMsg);
- setResults( results );
+ public ResultsMessage(List<? extends List<?>> results, String[] columnNames, String[] dataTypes){
+ this.results = results;
setFirstRow( 1 );
- setLastRow( results.length );
+ setLastRow( results.size() );
this.columnNames = columnNames;
this.dataTypes = dataTypes;
}
-
- public List[] getResults() {
+
+ public List<? extends List<?>> getResultsList() {
return results;
}
+
+ /**
+ * @deprecated see {@link #getResultsList()}
+ * @return
+ */
+ public List<?>[] getResults() {
+ return results.toArray(new List[results.size()]);
+ }
- public void setResults(List[] results) {
- this.results = results;
+ public void setResults(List<?>[] results) {
+ this.results = Arrays.asList(results);
}
public String[] getColumnNames() {
@@ -341,7 +334,7 @@
*/
public String toString() {
return new StringBuffer("ResultsMessage rowCount=") //$NON-NLS-1$
- .append(results == null ? 0 : results.length)
+ .append(results == null ? 0 : results.size())
.append(" finalRow=") //$NON-NLS-1$
.append(finalRow)
.toString();
Modified: trunk/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -416,7 +416,7 @@
private Batch getCurrentBatch(ResultsMessage currentResultMsg) {
this.updatedPlanDescription = currentResultMsg.getPlanDescription();
- boolean isLast = currentResultMsg.getResults().length == 0 || currentResultMsg.getFinalRow() == currentResultMsg.getLastRow();
+ boolean isLast = currentResultMsg.getResultsList().size() == 0 || currentResultMsg.getFinalRow() == currentResultMsg.getLastRow();
Batch result = new Batch(currentResultMsg.getResults(), currentResultMsg.getFirstRow(), currentResultMsg.getLastRow(), isLast);
result.setLastRow(currentResultMsg.getFinalRow());
return result;
Modified: trunk/client/src/test/java/org/teiid/client/TestBatchSerializer.java
===================================================================
--- trunk/client/src/test/java/org/teiid/client/TestBatchSerializer.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/client/src/test/java/org/teiid/client/TestBatchSerializer.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -35,10 +35,10 @@
import java.util.Arrays;
import java.util.List;
-import org.teiid.client.BatchSerializer;
+import junit.framework.TestCase;
+
import org.teiid.core.types.DataTypeManager;
-import junit.framework.TestCase;
@@ -63,21 +63,22 @@
}
}
- private static void helpTestSerialization(String[] types, List[] batch) throws IOException, ClassNotFoundException {
+ private static void helpTestSerialization(String[] types, List<?>[] batch) throws IOException, ClassNotFoundException {
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(byteStream);
- BatchSerializer.writeBatch(out, types, batch);
+ List<List<?>> batchList = Arrays.asList(batch);
+ BatchSerializer.writeBatch(out, types, batchList);
out.flush();
byte[] bytes = byteStream.toByteArray();
ByteArrayInputStream bytesIn = new ByteArrayInputStream(bytes);
ObjectInputStream in = new ObjectInputStream(bytesIn);
- List[] newBatch = BatchSerializer.readBatch(in, types);
+ List<List<Object>> newBatch = BatchSerializer.readBatch(in, types);
out.close();
in.close();
- assertEqual(batch, newBatch);
+ assertTrue(batchList.equals(newBatch));
}
private static final String[] sampleBatchTypes = {DataTypeManager.DefaultDataTypes.BIG_DECIMAL,
@@ -164,14 +165,6 @@
helpTestSerialization(sampleBatchTypes, sampleBatch(833)); // A bunch of rows. This should also test large strings
}
- public void testSerializeBasicTypes_NoTypeHints() throws Exception {
- helpTestSerialization(null, sampleBatch(1));
- helpTestSerialization(null, sampleBatch(8));
- helpTestSerialization(null, sampleBatch(17));
- helpTestSerialization(null, sampleBatch(120));
- helpTestSerialization(null, sampleBatch(833));
- }
-
public void testSerializeBasicTypesWithNulls() throws Exception {
helpTestSerialization(sampleBatchTypes, sampleBatchWithNulls(1));
helpTestSerialization(sampleBatchTypes, sampleBatchWithNulls(8));
@@ -186,10 +179,7 @@
}
public void testSerializeNoData() throws Exception {
- helpTestSerialization(sampleBatchTypes, null);
- helpTestSerialization(null, null);
helpTestSerialization(sampleBatchTypes, new List[0]);
- helpTestSerialization(null, new List[0]);
}
public void testSerializeDatatypeMismatch() throws Exception {
Modified: trunk/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -797,7 +797,7 @@
private ResultsMessage exampleMessage(List<Object>[] results, String[] columnNames, String[] datatypes) {
RequestMessage request = new RequestMessage();
request.setExecutionId(REQUEST_ID);
- ResultsMessage resultsMsg = new ResultsMessage(request);
+ ResultsMessage resultsMsg = new ResultsMessage();
resultsMsg.setResults(results);
resultsMsg.setColumnNames(columnNames);
resultsMsg.setDataTypes(datatypes);
@@ -834,7 +834,7 @@
private static ResultsMessage exampleResultsMsg4(int begin, int length, boolean lastBatch) {
RequestMessage request = new RequestMessage();
request.setExecutionId(REQUEST_ID);
- ResultsMessage resultsMsg = new ResultsMessage(request);
+ ResultsMessage resultsMsg = new ResultsMessage();
List[] results = exampleResults1(length, begin);
resultsMsg.setResults(results);
resultsMsg.setColumnNames(new String[] { "IntKey" }); //$NON-NLS-1$
@@ -862,7 +862,7 @@
@Test public void testDateType() throws SQLException {
RequestMessage request = new RequestMessage();
request.setExecutionId(REQUEST_ID);
- ResultsMessage resultsMsg = new ResultsMessage(request);
+ ResultsMessage resultsMsg = new ResultsMessage();
resultsMsg.setResults(new List[] {Arrays.asList(new Timestamp(0))});
resultsMsg.setColumnNames(new String[] { "TS" }); //$NON-NLS-1$
resultsMsg.setDataTypes(new String[] { JDBCSQLTypeInfo.TIMESTAMP });
Modified: trunk/client/src/test/java/org/teiid/jdbc/TestCallableStatement.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestCallableStatement.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestCallableStatement.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -38,9 +38,6 @@
import org.teiid.client.metadata.ParameterInfo;
import org.teiid.client.security.LogonResult;
import org.teiid.core.types.JDBCSQLTypeInfo;
-import org.teiid.jdbc.CallableStatementImpl;
-import org.teiid.jdbc.ConnectionImpl;
-import org.teiid.jdbc.ResultSetImpl;
import org.teiid.net.ServerConnection;
@@ -68,7 +65,7 @@
RequestMessage request = new RequestMessage();
request.setExecutionId(1);
- ResultsMessage resultsMsg = new ResultsMessage(request);
+ ResultsMessage resultsMsg = new ResultsMessage();
List[] results = new List[] {Arrays.asList(null, null, null), Arrays.asList(null, 1, 2)};
resultsMsg.setResults(results);
resultsMsg.setColumnNames(new String[] { "IntNum", "Out1", "Out2" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Modified: trunk/common-core/src/main/java/org/teiid/core/types/DataTypeManager.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/DataTypeManager.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/common-core/src/main/java/org/teiid/core/types/DataTypeManager.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -126,23 +126,40 @@
}
}
- private static Map<Class<?>, ValueCache<?>> valueMaps = new HashMap<Class<?>, ValueCache<?>>(128);
- private static HashedValueCache<String> stringCache = new HashedValueCache<String>(17) {
+ public static class WeakReferenceHashedValueCache<T> extends HashedValueCache<T> {
+ public WeakReferenceHashedValueCache(int size) {
+ super(size);
+ }
+
+ public T getByHash(Object obj) {
+ int index = hash(obj.hashCode()) & (cache.length - 1);
+ return get(index);
+ }
+
@Override
- protected Object get(int index) {
- WeakReference<?> ref = (WeakReference<?>) cache[index];
+ protected T get(int index) {
+ WeakReference<T> ref = (WeakReference<T>) cache[index];
if (ref != null) {
- return ref.get();
+ T result = ref.get();
+ if (result == null) {
+ cache[index] = null;
+ }
+ return result;
}
return null;
}
@Override
- protected void set(int index, String value) {
- cache[index] = new WeakReference<Object>(value);
- }
+ protected void set(int index, T value) {
+ cache[index] = new WeakReference<T>(value);
+ }
+ }
+
+ private static Map<Class<?>, ValueCache<?>> valueMaps = new HashMap<Class<?>, ValueCache<?>>(128);
+ private static HashedValueCache<String> stringCache = new WeakReferenceHashedValueCache<String>(17) {
+
@Override
protected int primaryHash(String value) {
if (value.length() < 14) {
@@ -536,21 +553,7 @@
valueMaps.put(DefaultDataClasses.DATE, new HashedValueCache<Date>(14));
valueMaps.put(DefaultDataClasses.TIME, new HashedValueCache<Time>(14));
valueMaps.put(DefaultDataClasses.TIMESTAMP, new HashedValueCache<Timestamp>(14));
- valueMaps.put(DefaultDataClasses.BIG_DECIMAL, new HashedValueCache<BigDecimal>(16) {
- @Override
- protected Object get(int index) {
- WeakReference<?> ref = (WeakReference<?>) cache[index];
- if (ref != null) {
- return ref.get();
- }
- return null;
- }
-
- @Override
- protected void set(int index, BigDecimal value) {
- cache[index] = new WeakReference<BigDecimal>(value);
- }
- });
+ valueMaps.put(DefaultDataClasses.BIG_DECIMAL, new WeakReferenceHashedValueCache<BigDecimal>(16));
valueMaps.put(DefaultDataClasses.STRING, stringCache);
}
}
Added: trunk/engine/src/main/java/org/teiid/common/buffer/AutoCleanupUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/AutoCleanupUtil.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/AutoCleanupUtil.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.common.buffer;
+
+import java.lang.ref.PhantomReference;
+import java.lang.ref.ReferenceQueue;
+import java.util.Collections;
+import java.util.IdentityHashMap;
+import java.util.Set;
+
+public class AutoCleanupUtil {
+
+ public interface Removable {
+ public void remove();
+ }
+
+ static final class PhantomCleanupReference extends PhantomReference<Object> {
+
+ private Removable removable;
+
+ public PhantomCleanupReference(Object referent, Removable removable) {
+ super(referent, QUEUE);
+ this.removable = removable;
+ }
+
+ public void cleanup() {
+ try {
+ this.removable.remove();
+ } finally {
+ this.removable = null;
+ this.clear();
+ }
+ }
+ }
+
+ private static ReferenceQueue<Object> QUEUE = new ReferenceQueue<Object>();
+ private static final Set<PhantomReference<Object>> REFERENCES = Collections.synchronizedSet(Collections.newSetFromMap(new IdentityHashMap<PhantomReference<Object>, Boolean>()));
+
+ public static void setCleanupReference(Object o, Removable r) {
+ REFERENCES.add(new PhantomCleanupReference(o, r));
+ doCleanup();
+ }
+
+ public static void doCleanup() {
+ for (int i = 0; i < 10; i++) {
+ PhantomCleanupReference ref = (PhantomCleanupReference)QUEUE.poll();
+ if (ref == null) {
+ break;
+ }
+ ref.cleanup();
+ REFERENCES.remove(ref);
+ }
+ }
+}
Property changes on: trunk/engine/src/main/java/org/teiid/common/buffer/AutoCleanupUtil.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/BatchManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/BatchManager.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/BatchManager.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -22,36 +22,29 @@
package org.teiid.common.buffer;
+import java.lang.ref.Reference;
+import java.util.List;
+
import org.teiid.core.TeiidComponentException;
+/**
+ * Acts as a combination serializer/cachemanager
+ */
public interface BatchManager {
- public interface CleanupHook {
-
- void cleanup();
-
- }
+ List<List<?>> getBatch(Long batch, boolean retain) throws TeiidComponentException;
- public interface ManagedBatch {
-
- TupleBatch getBatch(boolean cache, String[] types) throws TeiidComponentException;
-
- void remove();
-
- void setPrefersMemory(boolean prefers);
-
- /**
- * Get an object that can cleaup the {@link ManagedBatch}, but does not hold a hard reference to
- * the {@link ManagedBatch} or the {@link BatchManager}
- * @return
- */
- CleanupHook getCleanupHook();
-
- }
+ void remove(Long batch);
- ManagedBatch createManagedBatch(TupleBatch batch, boolean softCache) throws TeiidComponentException;
+ void setPrefersMemory(boolean prefers);
+ boolean prefersMemory();
+
+ Long createManagedBatch(List<? extends List<?>> batch) throws TeiidComponentException;
+
void remove();
- FileStore createStorage(String prefix);
+ Reference<? extends BatchManager> getBatchManagerReference();
+
+ String[] getTypes();
}
Added: trunk/engine/src/main/java/org/teiid/common/buffer/Cache.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/Cache.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/Cache.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer;
+
+import java.util.Collection;
+
+import org.teiid.core.TeiidComponentException;
+
+/**
+ * Represents the storage strategy for the {@link BufferManager}
+ */
+public interface Cache extends StorageManager {
+ void createCacheGroup(Long gid);
+ Collection<Long> removeCacheGroup(Long gid);
+ void addToCacheGroup(Long gid, Long oid); //called prior to adding an entry
+ CacheEntry get(Long id, Serializer<?> serializer) throws TeiidComponentException;
+ void add(CacheEntry entry, Serializer<?> s);
+ void remove(Long gid, Long id);
+}
\ No newline at end of file
Property changes on: trunk/engine/src/main/java/org/teiid/common/buffer/Cache.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/engine/src/main/java/org/teiid/common/buffer/CacheEntry.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/CacheEntry.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/CacheEntry.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer;
+
+import java.lang.ref.WeakReference;
+
+public class CacheEntry {
+ private boolean persistent;
+ private Object object;
+ private int sizeEstimate;
+ private WeakReference<? extends Serializer<?>> serializer;
+ private Long id;
+
+ public CacheEntry(Long id) {
+ this.id = id;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ @Override
+ public int hashCode() {
+ return getId().hashCode();
+ }
+
+ public int getSizeEstimate() {
+ return sizeEstimate;
+ }
+
+ public void setSizeEstimate(int sizeEstimate) {
+ this.sizeEstimate = sizeEstimate;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof CacheEntry)) {
+ return false;
+ }
+ return getId().equals(((CacheEntry)obj).getId());
+ }
+
+ @Override
+ public String toString() {
+ return getId().toString();
+ }
+
+ public Object nullOut() {
+ Object result = getObject();
+ setObject(null);
+ setSerializer(null);
+ return result;
+ }
+
+ public void setObject(Object object) {
+ this.object = object;
+ }
+
+ public Object getObject() {
+ return object;
+ }
+
+ public void setPersistent(boolean persistent) {
+ this.persistent = persistent;
+ }
+
+ public boolean isPersistent() {
+ return persistent;
+ }
+
+ public void setSerializer(WeakReference<? extends Serializer<?>> serializer) {
+ this.serializer = serializer;
+ }
+
+ public WeakReference<? extends Serializer<?>> getSerializer() {
+ return serializer;
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/engine/src/main/java/org/teiid/common/buffer/CacheEntry.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/FileStore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/FileStore.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/FileStore.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -25,20 +25,13 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.lang.ref.PhantomReference;
-import java.lang.ref.ReferenceQueue;
import java.util.Arrays;
-import java.util.Collections;
-import java.util.IdentityHashMap;
-import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
-import org.teiid.core.TeiidComponentException;
+import org.teiid.common.buffer.AutoCleanupUtil.Removable;
-public abstract class FileStore {
-
- private static ReferenceQueue<Object> QUEUE = new ReferenceQueue<Object>();
- private static final Set<PhantomReference<Object>> REFERENCES = Collections.newSetFromMap(new IdentityHashMap<PhantomReference<Object>, Boolean>());
-
+public abstract class FileStore implements Removable {
+
/**
* A customized buffered stream with an exposed buffer
*/
@@ -80,12 +73,8 @@
}
private void writeDirect(byte[] b, int off, int len) throws IOException {
- try {
- FileStore.this.write(b, off, len);
- bytesWritten = true;
- } catch (TeiidComponentException e) {
- throw new IOException(e);
- }
+ FileStore.this.write(b, off, len);
+ bytesWritten = true;
}
public void flushBuffer() throws IOException {
@@ -140,91 +129,59 @@
}
- static class CleanupReference extends PhantomReference<Object> {
-
- private FileStore store;
-
- public CleanupReference(Object referent, FileStore store) {
- super(referent, QUEUE);
- this.store = store;
- }
-
- public void cleanup() {
- try {
- this.store.remove();
- } finally {
- this.clear();
- }
- }
- }
+ private AtomicBoolean removed = new AtomicBoolean();
- private boolean removed;
- protected long len;
+ public abstract long getLength();
- public void setCleanupReference(Object o) {
- REFERENCES.add(new CleanupReference(o, this));
- for (int i = 0; i < 10; i++) {
- CleanupReference ref = (CleanupReference)QUEUE.poll();
- if (ref == null) {
- break;
- }
- ref.cleanup();
- REFERENCES.remove(ref);
- }
- }
+ public abstract void setLength(long length) throws IOException;
- public synchronized long getLength() {
- return len;
- }
-
- public synchronized void truncate(long length) throws TeiidComponentException {
- truncateDirect(length);
- len = length;
- }
-
- protected abstract void truncateDirect(long length) throws TeiidComponentException;
-
public int read(long fileOffset, byte[] b, int offSet, int length)
- throws TeiidComponentException {
- if (removed) {
- throw new TeiidComponentException("already removed"); //$NON-NLS-1$
+ throws IOException {
+ checkRemoved();
+ return readWrite(fileOffset, b, offSet, length, false);
+ }
+
+ private void checkRemoved() throws IOException {
+ if (removed.get()) {
+ throw new IOException("already removed"); //$NON-NLS-1$
}
- return readDirect(fileOffset, b, offSet, length);
}
- protected abstract int readDirect(long fileOffset, byte[] b, int offSet, int length)
- throws TeiidComponentException;
+ protected abstract int readWrite(long fileOffset, byte[] b, int offSet, int length, boolean write)
+ throws IOException;
- public void readFully(long fileOffset, byte[] b, int offSet, int length) throws TeiidComponentException {
+ public void readFully(long fileOffset, byte[] b, int offSet, int length) throws IOException {
+ if (length == 0) {
+ return;
+ }
int n = 0;
do {
int count = this.read(fileOffset + n, b, offSet + n, length - n);
- if (count < 0) {
- throw new TeiidComponentException("not enough bytes available"); //$NON-NLS-1$
+ if (count <= 0 && length > 0) {
+ throw new IOException("not enough bytes available"); //$NON-NLS-1$
}
n += count;
} while (n < length);
}
- public synchronized long write(byte[] bytes, int offset, int length) throws TeiidComponentException {
- return write(len, bytes, offset, length);
+ public synchronized void write(byte[] bytes, int offset, int length) throws IOException {
+ write(getLength(), bytes, offset, length);
}
- public synchronized long write(long start, byte[] bytes, int offset, int length) throws TeiidComponentException {
- if (removed) {
- throw new TeiidComponentException("already removed"); //$NON-NLS-1$
- }
- writeDirect(start, bytes, offset, length);
- long result = len;
- len = Math.max(len, start + length);
- return result;
+ public void write(long start, byte[] bytes, int offset, int length) throws IOException {
+ int n = 0;
+ do {
+ checkRemoved();
+ int count = this.readWrite(start + n, bytes, offset + n, length - n, true);
+ if (count <= 0 && length > 0) {
+ throw new IOException("not enough bytes available"); //$NON-NLS-1$
+ }
+ n += count;
+ } while (n < length);
}
- protected abstract void writeDirect(long start, byte[] bytes, int offset, int length) throws TeiidComponentException;
-
- public synchronized void remove() {
- if (!this.removed) {
- this.removed = true;
+ public void remove() {
+ if (removed.compareAndSet(false, true)) {
this.removeDirect();
}
}
@@ -248,24 +205,20 @@
@Override
public int read(byte[] b, int off, int len) throws IOException {
- try {
- if (this.streamLength != -1 && len > this.streamLength) {
- len = (int)this.streamLength;
- }
- if (this.streamLength == -1 || this.streamLength > 0) {
- int bytes = FileStore.this.read(offset, b, off, len);
- if (bytes != -1) {
- this.offset += bytes;
- if (this.streamLength != -1) {
- this.streamLength -= bytes;
- }
+ if (this.streamLength != -1 && len > this.streamLength) {
+ len = (int)this.streamLength;
+ }
+ if (this.streamLength == -1 || this.streamLength > 0) {
+ int bytes = FileStore.this.read(offset, b, off, len);
+ if (bytes != -1) {
+ this.offset += bytes;
+ if (this.streamLength != -1) {
+ this.streamLength -= bytes;
}
- return bytes;
}
- return -1;
- } catch (TeiidComponentException e) {
- throw new IOException(e);
+ return bytes;
}
+ return -1;
}
};
}
@@ -284,11 +237,7 @@
@Override
public void write(byte[] b, int off, int len) throws IOException {
- try {
- FileStore.this.write(b, off, len);
- } catch (TeiidComponentException e) {
- throw new IOException(e);
- }
+ FileStore.this.write(b, off, len);
}
};
}
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/FileStoreInputStreamFactory.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/FileStoreInputStreamFactory.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/FileStoreInputStreamFactory.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -42,7 +42,7 @@
public FileStoreInputStreamFactory(FileStore lobBuffer, String encoding) {
this.encoding = encoding;
this.lobBuffer = lobBuffer;
- this.lobBuffer.setCleanupReference(this);
+ AutoCleanupUtil.setCleanupReference(this, lobBuffer);
}
@Override
Added: trunk/engine/src/main/java/org/teiid/common/buffer/LightWeightCopyOnWriteList.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/LightWeightCopyOnWriteList.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/LightWeightCopyOnWriteList.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -0,0 +1,116 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer;
+
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.RandomAccess;
+
+/**
+ * Creates a copy of a reference list when modified.
+ *
+ * @param <T>
+ */
+public class LightWeightCopyOnWriteList<T> extends AbstractList<T> implements RandomAccess {
+
+ private List<T> list;
+ private boolean modified;
+
+ public LightWeightCopyOnWriteList(List<T> list) {
+ this.list = list;
+ }
+
+ @Override
+ public T get(int index) {
+ return list.get(index);
+ }
+
+ public List<T> getList() {
+ return list;
+ }
+
+ public void add(int index, T element) {
+ if (!modified) {
+ List<T> next = new ArrayList<T>(list.size() + 1);
+ next.addAll(list);
+ list = next;
+ modified = true;
+ }
+ list.add(index, element);
+ }
+
+ public T set(int index, T element) {
+ checkModified();
+ return list.set(index, element);
+ }
+
+ private void checkModified() {
+ if (!modified) {
+ list = new ArrayList<T>(list);
+ modified = true;
+ }
+ }
+
+ public boolean addAll(Collection<? extends T> c) {
+ return addAll(size(), c);
+ }
+
+ @Override
+ public boolean addAll(int index, Collection<? extends T> c) {
+ checkModified();
+ return list.addAll(index, c);
+ }
+
+ @Override
+ public T remove(int index) {
+ checkModified();
+ return list.remove(index);
+ }
+
+ @Override
+ public Object[] toArray() {
+ return list.toArray();
+ }
+
+ public <U extends Object> U[] toArray(U[] a) {
+ return list.toArray(a);
+ }
+
+ @Override
+ public void clear() {
+ if (!modified) {
+ list = new ArrayList<T>();
+ modified = true;
+ } else {
+ list.clear();
+ }
+ }
+
+ @Override
+ public int size() {
+ return list.size();
+ }
+
+}
Property changes on: trunk/engine/src/main/java/org/teiid/common/buffer/LightWeightCopyOnWriteList.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/LobManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/LobManager.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/LobManager.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -30,9 +30,10 @@
import java.sql.SQLException;
import java.sql.SQLXML;
import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.types.BaseLob;
@@ -58,10 +59,47 @@
* TODO: for temp tables we may need to have a copy by value management strategy
*/
public class LobManager {
- private Map<String, Streamable<?>> lobReferences = new ConcurrentHashMap<String, Streamable<?>>();
+
+ public enum ReferenceMode {
+ ATTACH,
+ CREATE,
+ REMOVE
+ }
+
+ private static class LobHolder {
+ Streamable<?> lob;
+ int referenceCount = 1;
+
+ public LobHolder(Streamable<?> lob) {
+ this.lob = lob;
+ }
+ }
+
+ private Map<String, LobHolder> lobReferences = Collections.synchronizedMap(new HashMap<String, LobHolder>());
private boolean inlineLobs = true;
private int maxMemoryBytes = DataTypeManager.MAX_LOB_MEMORY_BYTES;
+ private int[] lobIndexes;
+ private FileStore lobStore;
+ public LobManager(int[] lobIndexes, FileStore lobStore) {
+ this.lobIndexes = lobIndexes;
+ this.lobStore = lobStore;
+ }
+
+ public LobManager clone() {
+ LobManager clone = new LobManager(lobIndexes, null);
+ clone.inlineLobs = inlineLobs;
+ clone.maxMemoryBytes = maxMemoryBytes;
+ synchronized (lobReferences) {
+ for (Map.Entry<String, LobHolder> entry : lobReferences.entrySet()) {
+ LobHolder lobHolder = new LobHolder(entry.getValue().lob);
+ lobHolder.referenceCount = entry.getValue().referenceCount;
+ clone.lobReferences.put(entry.getKey(), lobHolder);
+ }
+ }
+ return clone;
+ }
+
public void setInlineLobs(boolean trackMemoryLobs) {
this.inlineLobs = trackMemoryLobs;
}
@@ -69,8 +107,9 @@
public void setMaxMemoryBytes(int maxMemoryBytes) {
this.maxMemoryBytes = maxMemoryBytes;
}
-
- public void updateReferences(int[] lobIndexes, List<?> tuple)
+
+ @SuppressWarnings("unchecked")
+ public void updateReferences(List<?> tuple, ReferenceMode mode)
throws TeiidComponentException {
for (int i = 0; i < lobIndexes.length; i++) {
Object anObj = tuple.get(lobIndexes[i]);
@@ -79,30 +118,53 @@
}
Streamable lob = (Streamable) anObj;
try {
- if (inlineLobs
+ if (lob.getReferenceStreamId() == null || (inlineLobs
&& (InputStreamFactory.getStorageMode(lob) == StorageMode.MEMORY
- || lob.length()*(lob instanceof ClobType?2:1) <= maxMemoryBytes)) {
+ || lob.length()*(lob instanceof ClobType?2:1) <= maxMemoryBytes))) {
lob.setReferenceStreamId(null);
continue;
}
} catch (SQLException e) {
//presumably the lob is bad, but let it slide for now
}
- if (lob.getReference() == null) {
- lob.setReference(getLobReference(lob.getReferenceStreamId()).getReference());
- } else {
- String id = lob.getReferenceStreamId();
- this.lobReferences.put(id, lob);
+ String id = lob.getReferenceStreamId();
+ LobHolder lobHolder = this.lobReferences.get(id);
+ switch (mode) {
+ case REMOVE:
+ if (lobHolder != null) {
+ lobHolder.referenceCount--;
+ if (lobHolder.referenceCount < 1) {
+ this.lobReferences.remove(id);
+ }
+ }
+ break;
+ case ATTACH:
+ if (lob.getReference() == null) {
+ if (lobHolder == null) {
+ throw new TeiidComponentException(QueryPlugin.Util.getString("ProcessWorker.wrongdata")); //$NON-NLS-1$
+ }
+ lob.setReference(lobHolder.lob.getReference());
+ }
+ break;
+ case CREATE:
+ if (lob.getReference() == null) {
+ throw new TeiidComponentException(QueryPlugin.Util.getString("ProcessWorker.wrongdata")); //$NON-NLS-1$
+ }
+ if (lobHolder == null) {
+ this.lobReferences.put(id, new LobHolder(lob));
+ } else {
+ lobHolder.referenceCount++;
+ }
}
}
}
public Streamable<?> getLobReference(String id) throws TeiidComponentException {
- Streamable<?> lob = this.lobReferences.get(id);
+ LobHolder lob = this.lobReferences.get(id);
if (lob == null) {
throw new TeiidComponentException(QueryPlugin.Util.getString("ProcessWorker.wrongdata")); //$NON-NLS-1$
}
- return lob;
+ return lob.lob;
}
public static int[] getLobIndexes(List<? extends Expression> expressions) {
@@ -123,12 +185,12 @@
return Arrays.copyOf(result, resultIndex);
}
- public void persist(FileStore lobStore) throws TeiidComponentException {
+ public void persist() throws TeiidComponentException {
// stream the contents of lob into file store.
- byte[] bytes = new byte[102400]; // 100k
+ byte[] bytes = new byte[1 << 14];
- for (Map.Entry<String, Streamable<?>> entry : this.lobReferences.entrySet()) {
- entry.setValue(persistLob(entry.getValue(), lobStore, bytes));
+ for (Map.Entry<String, LobHolder> entry : this.lobReferences.entrySet()) {
+ entry.getValue().lob = persistLob(entry.getValue().lob, lobStore, bytes);
}
}
@@ -202,4 +264,9 @@
public int getLobCount() {
return this.lobReferences.size();
}
+
+ public void remove() {
+ this.lobReferences.clear();
+
+ }
}
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/SPage.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/SPage.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/SPage.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -23,6 +23,7 @@
package org.teiid.common.buffer;
import java.lang.ref.PhantomReference;
+import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.util.ArrayList;
import java.util.Collections;
@@ -33,16 +34,12 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
-import org.teiid.common.buffer.BatchManager.CleanupHook;
-import org.teiid.common.buffer.BatchManager.ManagedBatch;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidRuntimeException;
/**
* A linked list Page entry in the tree
*
- * TODO: return the tuplebatch from getvalues, since that is what we're tracking
- *
* State cloning allows a single storage reference to be shared in many trees.
* A phantom reference is used for proper cleanup once cloned.
*
@@ -57,8 +54,8 @@
static class SearchResult {
int index;
SPage page;
- TupleBatch values;
- public SearchResult(int index, SPage page, TupleBatch values) {
+ List<List<?>> values;
+ public SearchResult(int index, SPage page, List<List<?>> values) {
this.index = index;
this.page = page;
this.values = values;
@@ -69,16 +66,21 @@
private static ReferenceQueue<Object> QUEUE = new ReferenceQueue<Object>();
static class CleanupReference extends PhantomReference<Object> {
- private CleanupHook batch;
+ private Long batch;
+ private Reference<? extends BatchManager> ref;
- public CleanupReference(Object referent, CleanupHook batch) {
+ public CleanupReference(Object referent, Long batch, Reference<? extends BatchManager> ref) {
super(referent, QUEUE);
this.batch = batch;
+ this.ref = ref;
}
public void cleanup() {
try {
- this.batch.cleanup();
+ BatchManager batchManager = ref.get();
+ if (batchManager != null) {
+ batchManager.remove(batch);
+ }
} finally {
this.clear();
}
@@ -92,28 +94,26 @@
private long id;
protected SPage next;
protected SPage prev;
- protected ManagedBatch managedBatch;
- private Object trackingObject;
- protected TupleBatch values;
- protected ArrayList<SPage> children;
- protected boolean cloned;
+ protected Long managedBatch;
+ protected Object trackingObject;
+ protected List<List<?>> values;
+ protected List<SPage> children;
SPage(STree stree, boolean leaf) {
this.stree = stree;
this.id = counter.getAndIncrement();
stree.pages.put(this.id, this);
- this.values = new TupleBatch(0, new ArrayList(stree.getPageSize(leaf)/4));
+ this.values = new ArrayList<List<?>>();
if (!leaf) {
- children = new ArrayList<SPage>(stree.getPageSize(false)/4);
+ children = new ArrayList<SPage>();
}
}
public SPage clone(STree tree) {
try {
if (this.managedBatch != null && trackingObject == null) {
- cloned = true;
this.trackingObject = new Object();
- CleanupReference managedBatchReference = new CleanupReference(trackingObject, managedBatch.getCleanupHook());
+ CleanupReference managedBatchReference = new CleanupReference(trackingObject, managedBatch, stree.getBatchManager(children == null).getBatchManagerReference());
REFERENCES.add(managedBatchReference);
}
SPage clone = (SPage) super.clone();
@@ -122,7 +122,7 @@
clone.children = new ArrayList<SPage>(children);
}
if (values != null) {
- clone.values = new TupleBatch(0, new ArrayList<List<?>>(values.getTuples()));
+ clone.values = new ArrayList<List<?>>(values);
}
return clone;
} catch (CloneNotSupportedException e) {
@@ -135,32 +135,32 @@
}
static SearchResult search(SPage page, List k, LinkedList<SearchResult> parent) throws TeiidComponentException {
- TupleBatch previousValues = null;
+ List<List<?>> previousValues = null;
for (;;) {
- TupleBatch values = page.getValues();
- int index = Collections.binarySearch(values.getTuples(), k, page.stree.comparator);
+ List<List<?>> values = page.getValues();
+ int index = Collections.binarySearch(values, k, page.stree.comparator);
int flippedIndex = - index - 1;
if (previousValues != null) {
if (flippedIndex == 0) {
//systemic weakness of the algorithm
- return new SearchResult(-previousValues.getTuples().size() - 1, page.prev, previousValues);
+ return new SearchResult(-previousValues.size() - 1, page.prev, previousValues);
}
if (parent != null && index != 0) {
page.stree.updateLock.lock();
try {
- index = Collections.binarySearch(values.getTuples(), k, page.stree.comparator);
+ index = Collections.binarySearch(values, k, page.stree.comparator);
if (index != 0) {
//for non-matches move the previous pointer over to this page
SPage childPage = page;
List oldKey = null;
- List newKey = page.stree.extractKey(values.getTuples().get(0));
+ List newKey = page.stree.extractKey(values.get(0));
for (Iterator<SearchResult> desc = parent.descendingIterator(); desc.hasNext();) {
SearchResult sr = desc.next();
int parentIndex = Math.max(0, -sr.index - 2);
if (oldKey == null) {
- oldKey = sr.values.getTuples().set(parentIndex, newKey);
- } else if (page.stree.comparator.compare(oldKey, sr.values.getTuples().get(parentIndex)) == 0 ) {
- sr.values.getTuples().set(parentIndex, newKey);
+ oldKey = sr.values.set(parentIndex, newKey);
+ } else if (page.stree.comparator.compare(oldKey, sr.values.get(parentIndex)) == 0 ) {
+ sr.values.set(parentIndex, newKey);
} else {
break;
}
@@ -174,7 +174,7 @@
}
}
}
- if (flippedIndex != values.getTuples().size() || page.next == null) {
+ if (flippedIndex != values.size() || page.next == null) {
return new SearchResult(index, page, values);
}
previousValues = values;
@@ -182,35 +182,32 @@
}
}
- protected void setValues(TupleBatch values) throws TeiidComponentException {
- if (managedBatch != null && !cloned) {
- managedBatch.remove();
+ protected void setValues(List<List<?>> values) throws TeiidComponentException {
+ if (values instanceof LightWeightCopyOnWriteList<?>) {
+ values = ((LightWeightCopyOnWriteList<List<?>>)values).getList();
}
- if (values.getTuples().size() < MIN_PERSISTENT_SIZE) {
+ if (managedBatch != null && trackingObject == null) {
+ stree.getBatchManager(children == null).remove(managedBatch);
+ managedBatch = null;
+ trackingObject = null;
+ }
+ if (values.size() < MIN_PERSISTENT_SIZE) {
this.values = values;
return;
- }
- this.values = null;
- if (children != null) {
- values.setDataTypes(stree.keytypes);
- } else {
- values.setDataTypes(stree.types);
+ } else if (stree.batchInsert && children == null && values.size() < stree.leafSize) {
+ this.values = values;
+ stree.incompleteInsert = this;
+ return;
}
- if (cloned) {
- cloned = false;
- trackingObject = null;
- }
- if (children != null) {
- managedBatch = stree.keyManager.createManagedBatch(values, true);
- } else {
- managedBatch = stree.leafManager.createManagedBatch(values, stree.preferMemory);
- }
+ this.values = null;
+ this.trackingObject = null;
+ managedBatch = stree.getBatchManager(children == null).createManagedBatch(values);
}
-
+
protected void remove(boolean force) {
if (managedBatch != null) {
- if (force || !cloned) {
- managedBatch.remove();
+ if (force || trackingObject == null) {
+ stree.getBatchManager(children == null).remove(managedBatch);
}
managedBatch = null;
trackingObject = null;
@@ -219,7 +216,7 @@
children = null;
}
- protected TupleBatch getValues() throws TeiidComponentException {
+ protected List<List<?>> getValues() throws TeiidComponentException {
if (values != null) {
return values;
}
@@ -234,19 +231,20 @@
REFERENCES.remove(ref);
ref.cleanup();
}
- if (children != null) {
- return managedBatch.getBatch(true, stree.keytypes);
+ List<List<?>> result = stree.getBatchManager(children == null).getBatch(managedBatch, true);
+ if (trackingObject != null) {
+ return new LightWeightCopyOnWriteList<List<?>>(result);
}
- return managedBatch.getBatch(true, stree.types);
+ return result;
}
- static void merge(LinkedList<SearchResult> places, TupleBatch nextValues, SPage current, TupleBatch currentValues)
+ static void merge(LinkedList<SearchResult> places, List<List<?>> nextValues, SPage current, List<List<?>> currentValues)
throws TeiidComponentException {
SearchResult parent = places.peekLast();
if (parent != null) {
- correctParents(parent.page, nextValues.getTuples().get(0), current.next, current);
+ correctParents(parent.page, nextValues.get(0), current.next, current);
}
- currentValues.getTuples().addAll(nextValues.getTuples());
+ currentValues.addAll(nextValues);
if (current.children != null) {
current.children.addAll(current.next.children);
}
@@ -292,19 +290,19 @@
public String toString() {
StringBuilder result = new StringBuilder();
try {
- TupleBatch tb = getValues();
- result.append(tb.getBeginRow());
+ List<List<?>> tb = getValues();
+ result.append(id);
if (children == null) {
- if (tb.getTuples().size() <= 1) {
- result.append(tb.getTuples());
+ if (tb.size() <= 1) {
+ result.append(tb);
} else {
- result.append("[").append(tb.getTuples().get(0)).append(" . ").append(tb.getTuples().size()). //$NON-NLS-1$ //$NON-NLS-2$
- append(" . ").append(tb.getTuples().get(tb.getTuples().size() - 1)).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
+ result.append("[").append(tb.get(0)).append(" . ").append(tb.size()). //$NON-NLS-1$ //$NON-NLS-2$
+ append(" . ").append(tb.get(tb.size() - 1)).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
}
} else {
result.append("["); //$NON-NLS-1$
for (int i = 0; i < children.size(); i++) {
- result.append(tb.getTuples().get(i)).append("->").append(children.get(i).getValues().getBeginRow()); //$NON-NLS-1$
+ result.append(tb.get(i)).append("->").append(children.get(i).getId()); //$NON-NLS-1$
if (i < children.size() - 1) {
result.append(", "); //$NON-NLS-1$
}
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/STree.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/STree.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/STree.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -27,15 +27,16 @@
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
import org.teiid.client.BatchSerializer;
+import org.teiid.common.buffer.LobManager.ReferenceMode;
import org.teiid.common.buffer.SPage.SearchResult;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidRuntimeException;
@@ -51,13 +52,13 @@
public enum InsertMode {ORDERED, NEW, UPDATE}
- private static final Random seedGenerator = new Random();
+ private static final Random seedGenerator = new Random(0);
protected int randomSeed;
private int mask = 1;
private int shift = 1;
- protected ConcurrentHashMap<Long, SPage> pages = new ConcurrentHashMap<Long, SPage>();
+ protected HashMap<Long, SPage> pages = new HashMap<Long, SPage>();
protected volatile SPage[] header = new SPage[] {new SPage(this, true)};
protected BatchManager keyManager;
protected BatchManager leafManager;
@@ -65,9 +66,9 @@
private int pageSize;
protected int leafSize;
protected int keyLength;
- protected String[] types;
- protected String[] keytypes;
- protected boolean preferMemory;
+ protected boolean batchInsert;
+ protected SPage incompleteInsert;
+ protected LobManager lobManager;
protected ReentrantLock updateLock = new ReentrantLock();
@@ -79,9 +80,10 @@
int pageSize,
int leafSize,
int keyLength,
- String[] types) {
+ LobManager lobManager) {
randomSeed = seedGenerator.nextInt() | 0x00000100; // ensure nonzero
this.keyManager = manager;
+ manager.setPrefersMemory(true);
this.leafManager = leafManager;
this.comparator = comparator;
this.pageSize = Math.max(pageSize, SPage.MIN_PERSISTENT_SIZE);
@@ -94,18 +96,20 @@
}
this.leafSize = leafSize;
this.keyLength = keyLength;
- this.types = types;
- this.keytypes = Arrays.copyOf(types, keyLength);
+ this.lobManager = lobManager;
}
public STree clone() {
updateLock.lock();
try {
STree clone = (STree) super.clone();
+ if (lobManager != null) {
+ clone.lobManager = lobManager.clone();
+ }
clone.updateLock = new ReentrantLock();
clone.rowCount = new AtomicInteger(rowCount.get());
//clone the pages
- clone.pages = new ConcurrentHashMap<Long, SPage>(pages);
+ clone.pages = new HashMap<Long, SPage>(pages);
for (Map.Entry<Long, SPage> entry : clone.pages.entrySet()) {
entry.setValue(entry.getValue().clone(clone));
}
@@ -143,23 +147,41 @@
SPage page = header[0];
oos.writeInt(this.rowCount.get());
while (true) {
- TupleBatch batch = page.getValues();
- BatchSerializer.writeBatch(oos, types, batch.getAllTuples());
+ List<List<?>> batch = page.getValues();
+ BatchSerializer.writeBatch(oos, leafManager.getTypes(), batch);
if (page.next == null) {
break;
}
}
}
+ public void setBatchInsert(boolean batchInsert) throws TeiidComponentException {
+ if (this.batchInsert == batchInsert) {
+ return;
+ }
+ this.batchInsert = batchInsert;
+ if (batchInsert || incompleteInsert == null) {
+ return;
+ }
+ SPage toFlush = incompleteInsert;
+ incompleteInsert = null;
+ if (toFlush.managedBatch != null) {
+ return;
+ }
+ toFlush.setValues(toFlush.getValues());
+ }
+
public void readValuesFrom(ObjectInputStream ois) throws IOException, ClassNotFoundException, TeiidComponentException {
int size = ois.readInt();
int sizeHint = this.getExpectedHeight(size);
+ batchInsert = true;
while (this.getRowCount() < size) {
- List[] batch = BatchSerializer.readBatch(ois, types);
+ List<List<Object>> batch = BatchSerializer.readBatch(ois, leafManager.getTypes());
for (List list : batch) {
this.insert(list, InsertMode.ORDERED, sizeHint);
}
}
+ batchInsert = false;
}
protected SPage findChildTail(SPage page) {
@@ -221,7 +243,7 @@
if (places != null) {
places.add(s);
}
- if ((s.index == -1 && s.page == header[i]) || s.values.getTuples().isEmpty()) {
+ if ((s.index == -1 && s.page == header[i]) || s.values.isEmpty()) {
x = null;
continue; //start at the beginning of the next level
}
@@ -236,7 +258,7 @@
if (!matched) {
return null;
}
- return s.values.getTuples().get(index);
+ return s.values.get(index);
}
x = x.children.get(index);
}
@@ -250,13 +272,16 @@
public List insert(List tuple, InsertMode mode, int sizeHint) throws TeiidComponentException {
LinkedList<SearchResult> places = new LinkedList<SearchResult>();
List match = null;
+ if (this.lobManager != null) {
+ this.lobManager.updateReferences(tuple, ReferenceMode.CREATE);
+ }
if (mode == InsertMode.ORDERED) {
SPage last = null;
while (last == null || last.children != null) {
last = findChildTail(last);
//TODO: do this lazily
- TupleBatch batch = last.getValues();
- places.add(new SearchResult(-batch.getTuples().size() -1, last, batch));
+ List<List<?>> batch = last.getValues();
+ places.add(new SearchResult(-batch.size() -1, last, batch));
}
} else {
match = find(tuple, places);
@@ -266,8 +291,11 @@
}
SearchResult last = places.getLast();
SPage page = last.page;
- last.values.getTuples().set(last.index, tuple);
+ last.values.set(last.index, tuple);
page.setValues(last.values);
+ if (this.lobManager != null) {
+ this.lobManager.updateReferences(tuple, ReferenceMode.REMOVE);
+ }
return match;
}
}
@@ -279,7 +307,7 @@
} else {
level = randomLevel();
}
- } else if (!places.isEmpty() && places.getLast().values.getTuples().size() == getPageSize(true)) {
+ } else if (!places.isEmpty() && places.getLast().values.size() == getPageSize(true)) {
int row = rowCount.get();
while (row != 0 && row%getPageSize(true) == 0) {
row = (row - getPageSize(true) + 1)/getPageSize(true);
@@ -295,8 +323,8 @@
for (int i = 0; i <= level; i++) {
if (places.isEmpty()) {
SPage newHead = new SPage(this, false);
- TupleBatch batch = newHead.getValues();
- batch.getTuples().add(key);
+ List<List<?>> batch = newHead.getValues();
+ batch.add(key);
newHead.setValues(batch);
newHead.children.add(page);
header[i] = newHead;
@@ -333,9 +361,9 @@
SPage page = result.page;
int index = -result.index - 1;
boolean leaf = !(value instanceof SPage);
- if (result.values.getTuples().size() == getPageSize(leaf)) {
+ if (result.values.size() == getPageSize(leaf)) {
SPage nextPage = new SPage(this, leaf);
- TupleBatch nextValues = nextPage.getValues();
+ List<List<?>> nextValues = nextPage.getValues();
nextPage.next = page.next;
nextPage.prev = page;
if (nextPage.next != null) {
@@ -345,8 +373,8 @@
boolean inNext = false;
if (!ordered) {
//split the values
- nextValues.getTuples().addAll(result.values.getTuples().subList(getPageSize(leaf)/2, getPageSize(leaf)));
- result.values.getTuples().subList(getPageSize(leaf)/2, getPageSize(leaf)).clear();
+ nextValues.addAll(result.values.subList(getPageSize(leaf)/2, getPageSize(leaf)));
+ result.values.subList(getPageSize(leaf)/2, getPageSize(leaf)).clear();
if (!leaf) {
nextPage.children.addAll(page.children.subList(getPageSize(leaf)/2, getPageSize(false)));
page.children.subList(getPageSize(false)/2, getPageSize(false)).clear();
@@ -359,7 +387,7 @@
}
page.setValues(result.values);
if (parent != null) {
- List min = nextPage.getValues().getTuples().get(0);
+ List min = nextPage.getValues().get(0);
SPage.correctParents(parent.page, min, page, nextPage);
}
} else {
@@ -377,12 +405,12 @@
return page;
}
- static void setValue(int index, List key, Object value, TupleBatch values, SPage page) {
+ static void setValue(int index, List key, Object value, List<List<?>> values, SPage page) {
if (value instanceof SPage) {
- values.getTuples().add(index, key);
+ values.add(index, key);
page.children.add(index, (SPage) value);
} else {
- values.getTuples().add(index, (List)value);
+ values.add(index, (List)value);
}
}
@@ -398,13 +426,13 @@
if (searchResult.index < 0) {
continue;
}
- searchResult.values.getTuples().remove(searchResult.index);
+ searchResult.values.remove(searchResult.index);
boolean leaf = true;
if (searchResult.page.children != null) {
leaf = false;
searchResult.page.children.remove(searchResult.index);
}
- int size = searchResult.values.getTuples().size();
+ int size = searchResult.values.size();
if (size == 0) {
if (header[i] != searchResult.page) {
searchResult.page.remove(false);
@@ -431,15 +459,15 @@
} else if (size < getPageSize(leaf)/2) {
//check for merge
if (searchResult.page.next != null) {
- TupleBatch nextValues = searchResult.page.next.getValues();
- if (nextValues.getTuples().size() < getPageSize(leaf)/4) {
+ List<List<?>> nextValues = searchResult.page.next.getValues();
+ if (nextValues.size() < getPageSize(leaf)/4) {
SPage.merge(places, nextValues, searchResult.page, searchResult.values);
continue;
}
}
if (searchResult.page.prev != null) {
- TupleBatch prevValues = searchResult.page.prev.getValues();
- if (prevValues.getTuples().size() < getPageSize(leaf)/4) {
+ List<List<?>> prevValues = searchResult.page.prev.getValues();
+ if (prevValues.size() < getPageSize(leaf)/4) {
SPage.merge(places, searchResult.values, searchResult.page.prev, prevValues);
continue;
}
@@ -447,6 +475,9 @@
}
searchResult.page.setValues(searchResult.values);
}
+ if (lobManager != null) {
+ lobManager.updateReferences(tuple, ReferenceMode.REMOVE);
+ }
return tuple;
}
@@ -498,11 +529,11 @@
}
public void setPreferMemory(boolean preferMemory) {
- this.preferMemory = preferMemory;
+ this.leafManager.setPrefersMemory(preferMemory);
}
public boolean isPreferMemory() {
- return preferMemory;
+ return this.leafManager.prefersMemory();
}
public ListNestedSortComparator getComparator() {
@@ -536,7 +567,7 @@
public void clearClonedFlags() {
for (SPage page : pages.values()) {
- page.cloned = false;
+ page.trackingObject = null;
//we don't really care about using synchronization or a volatile here
//since the worst case is that we'll just use gc cleanup
}
@@ -548,5 +579,12 @@
}
return pageSize;
}
+
+ BatchManager getBatchManager(boolean leaf) {
+ if (leaf) {
+ return leafManager;
+ }
+ return keyManager;
+ }
}
\ No newline at end of file
Added: trunk/engine/src/main/java/org/teiid/common/buffer/Serializer.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/Serializer.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/Serializer.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+/**
+ * Responsible for serializing {@link CacheEntry}s
+ * @param <T>
+ */
+public interface Serializer<T> {
+ void serialize(T obj, ObjectOutputStream oos) throws IOException;
+ T deserialize(ObjectInputStream ois) throws IOException, ClassNotFoundException;
+ boolean useSoftCache();
+ Long getId();
+}
\ No newline at end of file
Property changes on: trunk/engine/src/main/java/org/teiid/common/buffer/Serializer.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/TupleBatch.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/TupleBatch.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/TupleBatch.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -22,17 +22,11 @@
package org.teiid.common.buffer;
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import org.teiid.client.BatchSerializer;
-
/**
* Represents a set of indexed tuples. The {@link #getBeginRow beginning row}
* is the first row contained in this batch; if it equals "1" then it is the
@@ -40,28 +34,17 @@
* tuples. The {@link #getEndRow ending row} is the last row contained in
* this tuple batch; it is equal to the beginning row plus the
* {@link #getRowCount number of rows} contained in this batch, minus one.
- * This object is immutable and Serializable;
*/
-public class TupleBatch implements Externalizable {
+public class TupleBatch {
private static final long serialVersionUID = 6304443387337336957L;
private int rowOffset;
- private List<List<?>> tuples;
+ protected List<List<?>> tuples;
// Optional state
private boolean terminationFlag = false;
- // for distributed cache purposes
- private String[] preservedTypes;
-
- /**
- * Contains ordered data types of each of the columns in the batch. Although it is not serialized,
- * this array is a serialization aid and must be set before serialization and deserialization using
- * the setDataTypes method.
- */
- private transient String[] types;
-
/** Required to honor Externalizable contract */
public TupleBatch() {
}
@@ -152,14 +135,6 @@
this.terminationFlag = terminationFlag;
}
- public void setDataTypes(String[] types) {
- this.types = types;
- }
-
- public String[] getDataTypes() {
- return types;
- }
-
public boolean containsRow(int row) {
return rowOffset <= row && getEndRow() >= row;
}
@@ -179,31 +154,8 @@
return s.toString();
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- rowOffset = in.readInt();
- terminationFlag = in.readBoolean();
- preservedTypes = (String[])in.readObject();
- if (types == null) {
- types = preservedTypes;
- }
- tuples = new ArrayList<List<?>>();
- for (List tuple : BatchSerializer.readBatch(in, types)) {
- tuples.add(tuple);
- }
- }
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeInt(this.rowOffset);
- out.writeBoolean(terminationFlag);
- out.writeObject(this.preservedTypes);
- BatchSerializer.writeBatch(out, types, getAllTuples());
- }
-
public void setRowOffset(int rowOffset) {
this.rowOffset = rowOffset;
}
-
- public void preserveTypes() {
- this.preservedTypes = types;
- }
}
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -48,7 +48,7 @@
private SPage bound;
private int boundIndex = -1;
- private TupleBatch values;
+ private List<List<?>> values;
private boolean updated;
private boolean direction;
@@ -106,7 +106,7 @@
if (boundIndex < 0) {
//we are guaranteed by find to not get back the -1 index, unless
//there are no tuples, in which case a bound of -1 is fine
- boundIndex = Math.min(upper.values.getTuples().size(), -boundIndex -1) - 1;
+ boundIndex = Math.min(upper.values.size(), -boundIndex -1) - 1;
}
if (!direction) {
values = upper.values;
@@ -122,7 +122,7 @@
if (page != bound || values == null) {
values = bound.getValues();
}
- boundIndex = values.getTuples().size() - 1;
+ boundIndex = values.size() - 1;
}
}
@@ -173,14 +173,14 @@
continue;
}
if (values != null) {
- int possibleIndex = Collections.binarySearch(values.getTuples(), newValue, tree.comparator);
+ int possibleIndex = Collections.binarySearch(values, newValue, tree.comparator);
if (possibleIndex >= 0) {
//value exists in the current page
index = possibleIndex;
- return values.getTuples().get(possibleIndex);
+ return values.get(possibleIndex);
}
//check for end/terminal conditions
- if (direction && possibleIndex == -values.getTuples().size() -1) {
+ if (direction && possibleIndex == -values.size() -1) {
if (page.next == null) {
resetState();
return null;
@@ -199,7 +199,7 @@
if (!setPage(newValue)) {
continue;
}
- return values.getTuples().get(index);
+ return values.get(index);
}
if (page == null) {
if (inPartial) {
@@ -213,11 +213,11 @@
if (direction) {
index = 0;
} else {
- index = values.getTuples().size() - 1;
+ index = values.size() - 1;
}
}
- if (index >= 0 && index < values.getTuples().size()) {
- List<?> result = values.getTuples().get(index);
+ if (index >= 0 && index < values.size()) {
+ List<?> result = values.get(index);
if (page == bound && index == boundIndex) {
resetState();
page = null; //terminate
@@ -257,7 +257,7 @@
* @throws TeiidComponentException
*/
public void update(List<?> tuple) throws TeiidComponentException {
- values.getTuples().set(index - getOffset(), tuple);
+ values.set(index - getOffset(), tuple);
updated = true;
}
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -28,7 +28,7 @@
import java.util.Map;
import java.util.TreeMap;
-import org.teiid.common.buffer.BatchManager.ManagedBatch;
+import org.teiid.common.buffer.LobManager.ReferenceMode;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.types.Streamable;
@@ -64,33 +64,23 @@
private BatchManager manager;
private String tupleSourceID;
private List<? extends Expression> schema;
- private String[] types;
private int batchSize;
private int rowCount;
private boolean isFinal;
- private TreeMap<Integer, BatchManager.ManagedBatch> batches = new TreeMap<Integer, BatchManager.ManagedBatch>();
+ private TreeMap<Integer, Long> batches = new TreeMap<Integer, Long>();
private ArrayList<List<?>> batchBuffer;
private boolean removed;
private boolean forwardOnly;
- private boolean prefersMemory;
private LobManager lobManager;
- private int[] lobIndexes;
private String uuid;
- private FileStore lobStore;
- public TupleBuffer(BatchManager manager, String id, List<? extends Expression> schema, int[] lobIndexes, int batchSize) {
+ public TupleBuffer(BatchManager manager, String id, List<? extends Expression> schema, LobManager lobManager, int batchSize) {
this.manager = manager;
this.tupleSourceID = id;
this.schema = schema;
- this.types = getTypeNames(schema);
- this.lobIndexes = lobIndexes;
- if (this.lobIndexes != null) {
- this.lobManager = new LobManager();
- this.lobStore = this.manager.createStorage("_lobs"); //$NON-NLS-1$
- this.lobStore.setCleanupReference(this);
- }
+ this.lobManager = lobManager;
this.batchSize = batchSize;
}
@@ -112,12 +102,12 @@
}
public boolean isLobs() {
- return lobIndexes != null;
+ return lobManager != null;
}
public void addTuple(List<?> tuple) throws TeiidComponentException {
if (isLobs()) {
- lobManager.updateReferences(lobIndexes, tuple);
+ lobManager.updateReferences(tuple, ReferenceMode.CREATE);
}
this.rowCount++;
if (batchBuffer == null) {
@@ -125,7 +115,7 @@
}
batchBuffer.add(tuple);
if (batchBuffer.size() == batchSize) {
- saveBatch(false, false);
+ saveBatch(false);
}
}
@@ -144,7 +134,7 @@
//add the lob references only, since they may still be referenced later
if (isLobs()) {
for (List<?> tuple : batch.getTuples()) {
- lobManager.updateReferences(lobIndexes, tuple);
+ lobManager.updateReferences(tuple, ReferenceMode.CREATE);
}
}
}
@@ -154,7 +144,7 @@
throws TeiidComponentException {
assert this.rowCount <= rowCount;
if (this.rowCount != rowCount) {
- saveBatch(false, true);
+ saveBatch(true);
this.rowCount = rowCount;
}
}
@@ -163,15 +153,15 @@
if (this.batchBuffer != null) {
this.batchBuffer.clear();
}
- for (BatchManager.ManagedBatch batch : this.batches.values()) {
- batch.remove();
+ for (Long batch : this.batches.values()) {
+ this.manager.remove(batch);
}
this.batches.clear();
}
public void persistLobs() throws TeiidComponentException {
if (this.lobManager != null) {
- this.lobManager.persist(this.lobStore);
+ this.lobManager.persist();
}
}
@@ -180,26 +170,21 @@
* @throws TeiidComponentException
*/
public void saveBatch() throws TeiidComponentException {
- this.saveBatch(false, false);
+ this.saveBatch(false);
}
- void saveBatch(boolean finalBatch, boolean force) throws TeiidComponentException {
+ void saveBatch(boolean force) throws TeiidComponentException {
Assertion.assertTrue(!this.isRemoved());
if (batchBuffer == null || batchBuffer.isEmpty() || (!force && batchBuffer.size() < Math.max(1, batchSize / 32))) {
return;
}
- TupleBatch writeBatch = new TupleBatch(rowCount - batchBuffer.size() + 1, batchBuffer);
- if (finalBatch) {
- writeBatch.setTerminationFlag(true);
- }
- writeBatch.setDataTypes(types);
- BatchManager.ManagedBatch mbatch = manager.createManagedBatch(writeBatch, prefersMemory);
- this.batches.put(writeBatch.getBeginRow(), mbatch);
+ Long mbatch = manager.createManagedBatch(batchBuffer);
+ this.batches.put(rowCount - batchBuffer.size() + 1, mbatch);
batchBuffer = null;
}
public void close() throws TeiidComponentException {
- saveBatch(true, false);
+ saveBatch(false);
this.isFinal = true;
}
@@ -210,6 +195,8 @@
* @param row
* @return
* @throws TeiidComponentException
+ *
+ * TODO: a method to get the raw batch
*/
public TupleBatch getBatch(int row) throws TeiidComponentException {
TupleBatch result = null;
@@ -224,17 +211,20 @@
if (this.batchBuffer != null && !this.batchBuffer.isEmpty()) {
//this is just a sanity check to ensure we're not holding too many
//hard references to batches.
- saveBatch(isFinal, false);
+ saveBatch(false);
}
- Map.Entry<Integer, BatchManager.ManagedBatch> entry = batches.floorEntry(row);
+ Map.Entry<Integer, Long> entry = batches.floorEntry(row);
Assertion.isNotNull(entry);
- BatchManager.ManagedBatch batch = entry.getValue();
- result = batch.getBatch(!forwardOnly, types);
+ Long batch = entry.getValue();
+ List<List<?>> rows = manager.getBatch(batch, !forwardOnly);
+ result = new TupleBatch(entry.getKey(), rows);
+ if (isFinal && result.getEndRow() == rowCount) {
+ result.setTerminationFlag(true);
+ }
if (forwardOnly) {
batches.remove(entry.getKey());
}
}
- result.setDataTypes(types);
if (isFinal && result.getEndRow() == rowCount) {
result.setTerminationFlag(true);
}
@@ -246,8 +236,8 @@
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Removing TupleBuffer:", this.tupleSourceID); //$NON-NLS-1$
}
- if (this.lobStore != null) {
- this.lobStore.remove();
+ if (this.lobManager != null) {
+ this.lobManager.remove();
}
this.batchBuffer = null;
purge();
@@ -365,18 +355,11 @@
}
public void setPrefersMemory(boolean prefersMemory) {
- this.prefersMemory = prefersMemory;
- for (ManagedBatch batch : this.batches.values()) {
- batch.setPrefersMemory(prefersMemory);
- }
+ this.manager.setPrefersMemory(prefersMemory);
}
- public boolean isPrefersMemory() {
- return prefersMemory;
- }
-
public String[] getTypes() {
- return types;
+ return manager.getTypes();
}
public int getLobCount() {
Added: trunk/engine/src/main/java/org/teiid/common/buffer/impl/BitSetTree.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/BitSetTree.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/BitSetTree.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+ package org.teiid.common.buffer.impl;
+
+import java.util.BitSet;
+
+/**
+ * Extends a {@link BitSet} by adding a cumulative total and a
+ * first level index to speed queries against large bitsets.
+ */
+public class BitSetTree {
+
+ public static final int MAX_INDEX = (1 << 24) - 1;
+
+ private int bitsSet;
+ private int totalBits;
+ private short[] topVals = new short[1 << 9];
+ private BitSet bitSet = new BitSet();
+
+ public boolean get(int index) {
+ if (index > MAX_INDEX) {
+ throw new ArrayIndexOutOfBoundsException(index);
+ }
+ return bitSet.get(index);
+ }
+
+ /**
+ * Set the given bit at the index. It's expected that the
+ * bit currently has the opposite value.
+ * @param bitIndex
+ * @param value
+ */
+ public void set(int bitIndex, boolean value) {
+ if (bitIndex > MAX_INDEX) {
+ throw new ArrayIndexOutOfBoundsException(bitIndex);
+ }
+ bitSet.set(bitIndex, value);
+ if (bitIndex >= totalBits) {
+ totalBits = bitIndex + 1;
+ }
+ int topIndex = bitIndex >>> 15;
+ int increment = value?1:-1;
+ bitsSet+=increment;
+ topVals[topIndex]+=increment;
+ }
+
+ public int getTotalBits() {
+ return totalBits;
+ }
+
+ public int getBitsSet() {
+ return bitsSet;
+ }
+
+ public int nextClearBit(int fromIndex) {
+ int start = fromIndex >> 15;
+ for (int i = start; i < topVals.length; i++) {
+ if (topVals[i] < Short.MAX_VALUE) {
+ int searchFrom = fromIndex;
+ if (i > start) {
+ searchFrom = i << 15;
+ }
+ return bitSet.nextClearBit(searchFrom);
+ }
+ }
+ return -1;
+ }
+
+ public int nextSetBit(int fromIndex) {
+ if (bitsSet == 0) {
+ return -1;
+ }
+ int start = fromIndex >> 15;
+ for (int i = fromIndex >> 15; i < topVals.length; i++) {
+ if (topVals[i] > 0) {
+ int searchFrom = fromIndex;
+ if (i > start) {
+ searchFrom = i << 15;
+ }
+ return bitSet.nextSetBit(searchFrom);
+ }
+ }
+ return -1;
+ }
+
+}
Property changes on: trunk/engine/src/main/java/org/teiid/common/buffer/impl/BitSetTree.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -22,7 +22,6 @@
package org.teiid.common.buffer.impl;
-import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@@ -31,41 +30,41 @@
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.Arrays;
-import java.util.Comparator;
-import java.util.HashMap;
+import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.TreeMap;
-import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
+import org.teiid.client.BatchSerializer;
+import org.teiid.common.buffer.AutoCleanupUtil;
import org.teiid.common.buffer.BatchManager;
import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.Cache;
+import org.teiid.common.buffer.CacheEntry;
import org.teiid.common.buffer.FileStore;
import org.teiid.common.buffer.LobManager;
import org.teiid.common.buffer.STree;
+import org.teiid.common.buffer.Serializer;
import org.teiid.common.buffer.StorageManager;
-import org.teiid.common.buffer.TupleBatch;
import org.teiid.common.buffer.TupleBuffer;
-import org.teiid.common.buffer.BatchManager.ManagedBatch;
+import org.teiid.common.buffer.AutoCleanupUtil.Removable;
+import org.teiid.common.buffer.LobManager.ReferenceMode;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.types.DataTypeManager;
-import org.teiid.core.util.Assertion;
+import org.teiid.core.types.DataTypeManager.WeakReferenceHashedValueCache;
import org.teiid.dqp.internal.process.DQPConfiguration;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.logging.MessageLevel;
-import org.teiid.query.QueryPlugin;
import org.teiid.query.processor.relational.ListNestedSortComparator;
import org.teiid.query.sql.symbol.Expression;
@@ -74,477 +73,201 @@
* <p>Default implementation of BufferManager.</p>
* Responsible for creating/tracking TupleBuffers and providing access to the StorageManager.
* </p>
- * The buffering strategy attempts to purge batches from the least recently used TupleBuffer
- * from before (which wraps around circularly) the last used batch. This attempts to compensate
- * for our tendency to read buffers in a forward manner. If our processing algorithms are changed
- * to use alternating ascending/descending access, then the buffering approach could be replaced
- * with a simple LRU.
*
- * TODO: allow for cached stores to use lru - (result set/mat view)
- * TODO: account for row/content based sizing (difficult given value sharing)
* TODO: add detection of pinned batches to prevent unnecessary purging of non-persistent batches
* - this is not necessary for already persistent batches, since we hold a weak reference
*/
public class BufferManagerImpl implements BufferManager, StorageManager {
- private static final int TARGET_BYTES_PER_ROW = 1 << 11; //2k bytes per row
- private static final int IO_BUFFER_SIZE = 1 << 14;
- private static final int COMPACTION_THRESHOLD = 1 << 25; //start checking at 32 megs
-
- private final class CleanupHook implements org.teiid.common.buffer.BatchManager.CleanupHook {
-
- private Long id;
- private WeakReference<BatchManagerImpl> ref;
-
- CleanupHook(Long id, WeakReference<BatchManagerImpl> batchManager) {
- this.id = id;
- this.ref = batchManager;
- }
-
- public void cleanup() {
- BatchManagerImpl batchManager = ref.get();
- if (batchManager == null) {
- return;
- }
- cleanupManagedBatch(batchManager, id);
- }
-
- }
-
- private final class BatchManagerImpl implements BatchManager {
- final String id;
- volatile FileStore store;
- Map<Long, long[]> physicalMapping = new HashMap<Long, long[]>();
- long tail;
- ConcurrentSkipListSet<Long> freed = new ConcurrentSkipListSet<Long>();
- ReadWriteLock compactionLock = new ReentrantReadWriteLock();
- AtomicLong unusedSpace = new AtomicLong();
- private int[] lobIndexes;
+ private final class BatchManagerImpl implements BatchManager, Serializer<List<? extends List<?>>> {
+ final Long id;
SizeUtility sizeUtility;
private WeakReference<BatchManagerImpl> ref = new WeakReference<BatchManagerImpl>(this);
+ AtomicBoolean prefersMemory = new AtomicBoolean();
+ String[] types;
+ private LobManager lobManager;
- private BatchManagerImpl(String newID, int[] lobIndexes) {
+ private BatchManagerImpl(Long newID, String[] types) {
this.id = newID;
- this.store = createFileStore(id);
- this.store.setCleanupReference(this);
- this.lobIndexes = lobIndexes;
- this.sizeUtility = new SizeUtility();
+ this.sizeUtility = new SizeUtility(types);
+ this.types = types;
+ cache.createCacheGroup(newID);
}
- private void freeBatch(Long batch) {
- long[] info = physicalMapping.remove(batch);
- if (info != null) {
- unusedSpace.addAndGet(info[1]);
- if (info[0] + info[1] == tail) {
- tail -= info[1];
- }
- }
+ @Override
+ public Long getId() {
+ return id;
}
- public FileStore createStorage(String prefix) {
- return createFileStore(id+prefix);
+ public void setLobManager(LobManager lobManager) {
+ this.lobManager = lobManager;
}
-
+
@Override
- public ManagedBatch createManagedBatch(TupleBatch batch, boolean softCache)
- throws TeiidComponentException {
- ManagedBatchImpl mbi = new ManagedBatchImpl(batch, ref, softCache);
- mbi.addToCache(false);
- persistBatchReferences();
- return mbi;
+ public String[] getTypes() {
+ return types;
}
- private long getOffset() throws TeiidComponentException {
- if (store.getLength() <= compactionThreshold || unusedSpace.get() * 4 <= store.getLength() * 3) {
- return tail;
- }
- if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
- LogManager.logDetail(LogConstants.CTX_DQP, "Running full compaction on", id); //$NON-NLS-1$
- }
- byte[] buffer = new byte[IO_BUFFER_SIZE];
- TreeSet<long[]> bySize = new TreeSet<long[]>(new Comparator<long[]>() {
- @Override
- public int compare(long[] o1, long[] o2) {
- int signum = Long.signum(o1[1] - o2[1]);
- if (signum == 0) {
- //take the upper address first
- return Long.signum(o2[0] - o1[0]);
- }
- return signum;
- }
- });
- TreeSet<long[]> byAddress = new TreeSet<long[]>(new Comparator<long[]>() {
-
- @Override
- public int compare(long[] o1, long[] o2) {
- return Long.signum(o1[0] - o2[0]);
- }
- });
- bySize.addAll(physicalMapping.values());
- byAddress.addAll(physicalMapping.values());
- long lastEndAddress = 0;
- unusedSpace.set(0);
- long minFreeSpace = 1 << 11;
- while (!byAddress.isEmpty()) {
- long[] info = byAddress.pollFirst();
- bySize.remove(info);
-
- long currentOffset = info[0];
- long space = currentOffset - lastEndAddress;
- while (space > 0 && !bySize.isEmpty()) {
- long[] smallest = bySize.first();
- if (smallest[1] > space) {
- break;
- }
- bySize.pollFirst();
- byAddress.remove(smallest);
- move(smallest, lastEndAddress, buffer);
- space -= smallest[1];
- lastEndAddress += smallest[1];
- }
-
- if (space <= minFreeSpace) {
- unusedSpace.addAndGet(space);
- } else {
- move(info, lastEndAddress, buffer);
- }
- lastEndAddress = info[0] + info[1];
- }
- long oldLength = store.getLength();
- store.truncate(lastEndAddress);
- tail = lastEndAddress;
- if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
- LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Compacted store", id, "pre-size", oldLength, "post-size", store.getLength()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- return tail;
+ @Override
+ public boolean prefersMemory() {
+ return prefersMemory.get();
}
- private void move(long[] toMove, long newOffset, byte[] buffer) throws TeiidComponentException {
- long oldOffset = toMove[0];
- toMove[0] = newOffset;
- int size = (int)toMove[1];
- while (size > 0) {
- int toWrite = Math.min(IO_BUFFER_SIZE, size);
- store.readFully(oldOffset, buffer, 0, toWrite);
- store.write(newOffset, buffer, 0, toWrite);
- size -= toWrite;
- oldOffset += toWrite;
- newOffset += toWrite;
- }
+ @Override
+ public void setPrefersMemory(boolean prefers) {
+ //TODO: it's only expected to move from not preferring to prefefring
+ this.prefersMemory.set(prefers);
}
-
+
@Override
- public void remove() {
- this.store.remove();
+ public boolean useSoftCache() {
+ return prefersMemory.get();
}
@Override
- public String toString() {
- return id;
+ public Reference<? extends BatchManager> getBatchManagerReference() {
+ return ref;
}
- }
-
- /**
- * Holder for active batches
- */
- private class TupleBufferInfo {
- TreeMap<Long, ManagedBatchImpl> batches = new TreeMap<Long, ManagedBatchImpl>();
- Long lastUsed = null;
- ManagedBatchImpl removeBatch(Long row) {
- ManagedBatchImpl result = batches.remove(row);
- if (result != null) {
- activeBatchKB -= result.sizeEstimate;
- if (result.softCache) {
- BatchSoftReference ref = (BatchSoftReference)result.batchReference;
- if (ref != null) {
- maxReserveKB += ref.sizeEstimate;
- ref.sizeEstimate = 0;
- ref.clear();
+ @Override
+ public Long createManagedBatch(List<? extends List<?>> batch)
+ throws TeiidComponentException {
+ int sizeEstimate = getSizeEstimate(batch);
+ Long oid = batchAdded.getAndIncrement();
+ CacheEntry ce = new CacheEntry(oid);
+ ce.setObject(batch);
+ ce.setSizeEstimate(sizeEstimate);
+ ce.setSerializer(this.ref);
+ return addCacheEntry(ce, this);
+ }
+
+ @Override
+ public List<? extends List<?>> deserialize(ObjectInputStream ois)
+ throws IOException, ClassNotFoundException {
+ List<? extends List<?>> batch = BatchSerializer.readBatch(ois, types);
+ if (lobManager != null) {
+ for (List<?> list : batch) {
+ try {
+ lobManager.updateReferences(list, ReferenceMode.ATTACH);
+ } catch (TeiidComponentException e) {
+ throw new TeiidRuntimeException(e);
}
}
}
- return result;
+ return batch;
}
- }
-
- private final class ManagedBatchImpl implements ManagedBatch {
- private boolean persistent;
- private boolean softCache;
- private volatile TupleBatch activeBatch;
- private volatile Reference<TupleBatch> batchReference;
- private WeakReference<BatchManagerImpl> managerRef;
- private Long id;
- private LobManager lobManager;
- private int sizeEstimate;
- public ManagedBatchImpl(TupleBatch batch, WeakReference<BatchManagerImpl> ref, boolean softCache) {
- this.softCache = softCache;
- id = batchAdded.incrementAndGet();
- this.activeBatch = batch;
- this.managerRef = ref;
- BatchManagerImpl batchManager = ref.get();
- if (batchManager.lobIndexes != null) {
- this.lobManager = new LobManager();
- }
- sizeEstimate = (int) Math.max(1, batchManager.sizeUtility.getBatchSize(batch) / 1024);
- if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
- LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "Add batch to BufferManager", id, "with size estimate", sizeEstimate); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ @Override
+ public void serialize(List<? extends List<?>> obj,
+ ObjectOutputStream oos) throws IOException {
+ //it's expected that the containing structure has updated the lob manager
+ BatchSerializer.writeBatch(oos, types, obj);
}
- @Override
- public void setPrefersMemory(boolean prefers) {
- this.softCache = prefers;
- //TODO: could recreate the reference
+ public int getSizeEstimate(List<? extends List<?>> obj) {
+ return (int) Math.max(1, sizeUtility.getBatchSize(obj) / 1024);
}
-
- private void addToCache(boolean update) {
- BatchManagerImpl batchManager = managerRef.get();
- if (batchManager == null) {
- remove();
- return;
- }
- synchronized (activeBatches) {
- TupleBatch batch = this.activeBatch;
- if (batch == null) {
- return; //already removed
- }
- activeBatchKB += sizeEstimate;
- TupleBufferInfo tbi = null;
- if (update) {
- tbi = activeBatches.remove(batchManager.id);
- } else {
- tbi = activeBatches.get(batchManager.id);
- }
- if (tbi == null) {
- tbi = new TupleBufferInfo();
- update = true;
- }
- if (update) {
- activeBatches.put(batchManager.id, tbi);
- }
- tbi.batches.put(this.id, this);
- }
- }
-
+
+ @SuppressWarnings("unchecked")
@Override
- public TupleBatch getBatch(boolean cache, String[] types) throws TeiidComponentException {
- BatchManagerImpl batchManager = managerRef.get();
- if (batchManager == null) {
- remove();
- throw new AssertionError("Already removed"); //$NON-NLS-1$
- }
+ public List<List<?>> getBatch(Long batch, boolean retain)
+ throws TeiidComponentException {
+ cleanSoftReferences();
long reads = readAttempts.incrementAndGet();
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
- LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, batchManager.id, "getting batch", reads, "reference hits", referenceHit.get()); //$NON-NLS-1$ //$NON-NLS-2$
+ LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, id, "getting batch", batch, "total reads", reads, "reference hits", referenceHit.get()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- synchronized (activeBatches) {
- for (int i = 0; i < 10; i++) {
- BatchSoftReference ref = (BatchSoftReference)SOFT_QUEUE.poll();
- if (ref == null) {
- break;
- }
- maxReserveKB += ref.sizeEstimate;
- ref.sizeEstimate = 0;
- ref.clear();
- }
- TupleBufferInfo tbi = activeBatches.remove(batchManager.id);
- if (tbi != null) {
- boolean put = true;
- if (!cache) {
- tbi.removeBatch(this.id);
- if (tbi.batches.isEmpty()) {
- put = false;
- }
- }
- if (put) {
- tbi.lastUsed = this.id;
- activeBatches.put(batchManager.id, tbi);
- }
- }
+ CacheEntry ce = fastGet(batch, prefersMemory.get(), retain);
+ if (ce != null) {
+ return (List<List<?>>)(!retain?ce.nullOut():ce.getObject());
}
- persistBatchReferences();
synchronized (this) {
- TupleBatch batch = this.activeBatch;
- if (batch != null){
- return batch;
+ ce = fastGet(batch, prefersMemory.get(), retain);
+ if (ce != null) {
+ return (List<List<?>>)(!retain?ce.nullOut():ce.getObject());
}
- Reference<TupleBatch> ref = this.batchReference;
- this.batchReference = null;
- if (ref != null) {
- batch = ref.get();
- if (batch != null) {
- if (cache) {
- this.activeBatch = batch;
- addToCache(true);
- }
- referenceHit.getAndIncrement();
- return batch;
- }
- }
long count = readCount.incrementAndGet();
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
- LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, batchManager.id, id, "reading batch from disk, total reads:", count); //$NON-NLS-1$
+ LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, id, id, "reading batch", batch, "from storage, total reads:", count); //$NON-NLS-1$ //$NON-NLS-2$
}
- try {
- batchManager.compactionLock.readLock().lock();
- long[] info = batchManager.physicalMapping.get(this.id);
- ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(batchManager.store.createInputStream(info[0]), IO_BUFFER_SIZE));
- batch = new TupleBatch();
- batch.setRowOffset(ois.readInt());
- batch.setDataTypes(types);
- batch.readExternal(ois);
- batch.setDataTypes(null);
- if (lobManager != null) {
- for (List<?> tuple : batch.getTuples()) {
- lobManager.updateReferences(batchManager.lobIndexes, tuple);
- }
- }
- if (cache) {
- this.activeBatch = batch;
- addToCache(true);
- }
- return batch;
- } catch(IOException e) {
- throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", batchManager.id)); //$NON-NLS-1$
- } catch (ClassNotFoundException e) {
- throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", batchManager.id)); //$NON-NLS-1$
- } finally {
- batchManager.compactionLock.readLock().unlock();
- }
- }
- }
-
- public synchronized void persist() throws TeiidComponentException {
- final BatchManagerImpl batchManager = managerRef.get();
- if (batchManager == null) {
- remove();
- return;
- }
- boolean lockheld = false;
- try {
- TupleBatch batch = activeBatch;
- if (batch != null) {
- if (!persistent) {
- long count = writeCount.incrementAndGet();
- if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
- LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, batchManager.id, id, "writing batch to disk, total writes: ", count); //$NON-NLS-1$
- }
- if (lobManager != null) {
- for (List<?> tuple : batch.getTuples()) {
- lobManager.updateReferences(batchManager.lobIndexes, tuple);
- }
- }
- batchManager.compactionLock.writeLock().lock();
- Long free = null;
- while ((free = batchManager.freed.pollFirst()) != null) {
- batchManager.freeBatch(free);
- }
- lockheld = true;
- final long offset = batchManager.getOffset();
- ExtensibleBufferedOutputStream fsos = new ExtensibleBufferedOutputStream(new byte[IO_BUFFER_SIZE]) {
-
- @Override
- protected void flushDirect() throws IOException {
- try {
- batchManager.store.write(offset + bytesWritten, buf, 0, count);
- } catch (TeiidComponentException e) {
- throw new IOException(e);
- }
- }
- };
- ObjectOutputStream oos = new ObjectOutputStream(fsos);
- oos.writeInt(batch.getBeginRow());
- batch.writeExternal(oos);
- oos.close();
- long size = fsos.getBytesWritten();
- long[] info = new long[] {offset, size};
- batchManager.physicalMapping.put(this.id, info);
- batchManager.tail = Math.max(batchManager.tail, offset + size);
- if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
- LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, batchManager.id, id, "batch written starting at:", offset); //$NON-NLS-1$
- }
- }
- if (softCache) {
- this.batchReference = new BatchSoftReference(batch, SOFT_QUEUE, sizeEstimate);
- synchronized (activeBatches) {
- maxReserveKB -= sizeEstimate;
- }
- } else if (useWeakReferences) {
- this.batchReference = new WeakReference<TupleBatch>(batch);
- }
+ ce = cache.get(batch, this);
+ if (ce == null) {
+ throw new AssertionError("Batch not found in storage " + batch); //$NON-NLS-1$
}
- } catch (IOException e) {
- throw new TeiidComponentException(e);
- } catch (Throwable e) {
- throw new TeiidComponentException(e);
- } finally {
- persistent = true;
- activeBatch = null;
- if (lockheld) {
- batchManager.compactionLock.writeLock().unlock();
+ if (!retain) {
+ cache.remove(this.id, batch);
}
- }
+ ce.setSerializer(this.ref);
+ if (retain) {
+ addMemoryEntry(ce);
+ }
+ }
+ return (List<List<?>>)ce.getObject();
}
+
+ @Override
+ public void remove(Long batch) {
+ cleanSoftReferences();
+ BufferManagerImpl.this.remove(id, batch, prefersMemory.get());
+ }
+ @Override
public void remove() {
- activeBatch = null;
- batchReference = null;
- BatchManagerImpl batchManager = managerRef.get();
- if (batchManager != null) {
- cleanupManagedBatch(batchManager, id);
- }
+ removeCacheGroup(id, prefersMemory.get());
}
-
+
@Override
- public CleanupHook getCleanupHook() {
- return new CleanupHook(id, managerRef);
- }
-
- @Override
public String toString() {
- return "ManagedBatch " + managerRef.get() + " " + this.id + " " + activeBatch; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ return id.toString();
}
}
- private static class BatchSoftReference extends SoftReference<TupleBatch> {
+ private static class BatchSoftReference extends SoftReference<CacheEntry> {
private int sizeEstimate;
+ private Long key;
- public BatchSoftReference(TupleBatch referent,
- ReferenceQueue<? super TupleBatch> q, int sizeEstimate) {
+ public BatchSoftReference(CacheEntry referent,
+ ReferenceQueue<? super CacheEntry> q, int sizeEstimate) {
super(referent, q);
this.sizeEstimate = sizeEstimate;
+ this.key = referent.getId();
}
}
+
+ private static final int TARGET_BYTES_PER_ROW = 1 << 11; //2k bytes per row
+ private static ReferenceQueue<CacheEntry> SOFT_QUEUE = new ReferenceQueue<CacheEntry>();
- private static ReferenceQueue<? super TupleBatch> SOFT_QUEUE = new ReferenceQueue<TupleBatch>();
-
// Configuration
private int connectorBatchSize = BufferManager.DEFAULT_CONNECTOR_BATCH_SIZE;
private int processorBatchSize = BufferManager.DEFAULT_PROCESSOR_BATCH_SIZE;
//set to acceptable defaults for testing
private int maxProcessingKB = 1 << 11;
private Integer maxProcessingKBOrig;
- private int maxReserveKB = 1 << 25;
+ private AtomicInteger maxReserveKB = new AtomicInteger(1 << 18);
private volatile int reserveBatchKB;
private int maxActivePlans = DQPConfiguration.DEFAULT_MAX_ACTIVE_PLANS; //used as a hint to set the reserveBatchKB
private boolean useWeakReferences = true;
private boolean inlineLobs = true;
private int targetBytesPerRow = TARGET_BYTES_PER_ROW;
- private int compactionThreshold = COMPACTION_THRESHOLD;
private ReentrantLock lock = new ReentrantLock(true);
private Condition batchesFreed = lock.newCondition();
- private volatile int activeBatchKB = 0;
- private Map<String, TupleBufferInfo> activeBatches = new LinkedHashMap<String, TupleBufferInfo>();
+ private AtomicInteger activeBatchKB = new AtomicInteger();
+
+ //tiered memory entries. the first tier is just a queue of adds/gets. once accessed again, the entry moves to the tenured tier.
+ private LinkedHashMap<Long, CacheEntry> memoryEntries = new LinkedHashMap<Long, CacheEntry>(16, .75f, false);
+ private LinkedHashMap<Long, CacheEntry> tenuredMemoryEntries = new LinkedHashMap<Long, CacheEntry>(16, .75f, true);
+
+ private WeakReferenceHashedValueCache<CacheEntry> weakReferenceCache; //limited size based upon the memory settings
+ private ConcurrentHashMap<Long, BatchSoftReference> softCache = new ConcurrentHashMap<Long, BatchSoftReference>(); //"unlimitted" size maintained by reference queue
+
+ private Cache cache;
+
private Map<String, TupleReference> tupleBufferMap = new ConcurrentHashMap<String, TupleReference>();
private ReferenceQueue<TupleBuffer> tupleBufferQueue = new ReferenceQueue<TupleBuffer>();
- private StorageManager diskMgr;
-
private AtomicLong tsId = new AtomicLong();
private AtomicLong batchAdded = new AtomicLong();
private AtomicLong readCount = new AtomicLong();
@@ -603,60 +326,42 @@
this.processorBatchSize = processorBatchSize;
}
- /**
- * Add a storage manager to this buffer manager, order is unimportant
- * @param storageManager Storage manager to add
- */
- public void setStorageManager(StorageManager storageManager) {
- Assertion.isNotNull(storageManager);
- Assertion.isNull(diskMgr);
- this.diskMgr = storageManager;
- }
-
- public StorageManager getStorageManager() {
- return diskMgr;
- }
-
@Override
public TupleBuffer createTupleBuffer(final List elements, String groupName,
TupleSourceType tupleSourceType) {
- final String newID = String.valueOf(this.tsId.getAndIncrement());
+ final Long newID = this.tsId.getAndIncrement();
int[] lobIndexes = LobManager.getLobIndexes(elements);
- BatchManager batchManager = new BatchManagerImpl(newID, lobIndexes);
- TupleBuffer tupleBuffer = new TupleBuffer(batchManager, newID, elements, lobIndexes, getProcessorBatchSize(elements));
+ String[] types = TupleBuffer.getTypeNames(elements);
+ BatchManagerImpl batchManager = createBatchManager(newID, types);
+ LobManager lobManager = null;
+ FileStore lobStore = null;
+ if (lobIndexes != null) {
+ lobStore = createFileStore(newID + "_lobs"); //$NON-NLS-1$
+ lobManager = new LobManager(lobIndexes, lobStore);
+ batchManager.setLobManager(lobManager);
+ }
+ TupleBuffer tupleBuffer = new TupleBuffer(batchManager, String.valueOf(newID), elements, lobManager, getProcessorBatchSize(elements));
+ if (lobStore != null) {
+ AutoCleanupUtil.setCleanupReference(batchManager, lobStore);
+ }
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
- LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Creating TupleBuffer:", newID, elements, Arrays.toString(tupleBuffer.getTypes()), "of type", tupleSourceType); //$NON-NLS-1$ //$NON-NLS-2$
+ LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Creating TupleBuffer:", newID, elements, Arrays.toString(types), "of type", tupleSourceType); //$NON-NLS-1$ //$NON-NLS-2$
}
tupleBuffer.setInlineLobs(inlineLobs);
return tupleBuffer;
}
- private void cleanupManagedBatch(BatchManagerImpl batchManager, Long id) {
- synchronized (activeBatches) {
- TupleBufferInfo tbi = activeBatches.get(batchManager.id);
- if (tbi != null && tbi.removeBatch(id) != null) {
- if (tbi.batches.isEmpty()) {
- activeBatches.remove(batchManager.id);
- }
- }
- }
-
- if (batchManager.compactionLock.writeLock().tryLock()) {
- try {
- batchManager.freeBatch(id);
- } finally {
- batchManager.compactionLock.writeLock().unlock();
- }
- } else {
- batchManager.freed.add(id);
- }
- }
-
public STree createSTree(final List elements, String groupName, int keyLength) {
- String newID = String.valueOf(this.tsId.getAndIncrement());
+ Long newID = this.tsId.getAndIncrement();
int[] lobIndexes = LobManager.getLobIndexes(elements);
- BatchManager bm = new BatchManagerImpl(newID, lobIndexes);
- BatchManager keyManager = new BatchManagerImpl(String.valueOf(this.tsId.getAndIncrement()), null);
+ String[] types = TupleBuffer.getTypeNames(elements);
+ BatchManagerImpl bm = createBatchManager(newID, types);
+ LobManager lobManager = null;
+ if (lobIndexes != null) {
+ lobManager = new LobManager(lobIndexes, null); //persistence is not expected yet - later we might utilize storage for out-of-line lob values
+ bm.setLobManager(lobManager);
+ }
+ BatchManager keyManager = createBatchManager(this.tsId.getAndIncrement(), Arrays.copyOf(types, keyLength));
int[] compareIndexes = new int[keyLength];
for (int i = 1; i < compareIndexes.length; i++) {
compareIndexes[i] = i;
@@ -664,16 +369,33 @@
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Creating STree:", newID); //$NON-NLS-1$
}
- return new STree(keyManager, bm, new ListNestedSortComparator(compareIndexes), getProcessorBatchSize(elements), getProcessorBatchSize(elements.subList(0, keyLength)), keyLength, TupleBuffer.getTypeNames(elements));
+ return new STree(keyManager, bm, new ListNestedSortComparator(compareIndexes), getProcessorBatchSize(elements), getProcessorBatchSize(elements.subList(0, keyLength)), keyLength, lobManager);
}
+ private BatchManagerImpl createBatchManager(final Long newID, String[] types) {
+ BatchManagerImpl bm = new BatchManagerImpl(newID, types);
+ final AtomicBoolean prefersMemory = bm.prefersMemory;
+ AutoCleanupUtil.setCleanupReference(bm, new Removable() {
+
+ @Override
+ public void remove() {
+ BufferManagerImpl.this.removeCacheGroup(newID, prefersMemory.get());
+ }
+ });
+ return bm;
+ }
+
@Override
public FileStore createFileStore(String name) {
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Creating FileStore:", name); //$NON-NLS-1$
}
- return this.diskMgr.createFileStore(name);
+ return this.cache.createFileStore(name);
}
+
+ public Cache getCache() {
+ return cache;
+ }
public void setMaxActivePlans(int maxActivePlans) {
this.maxActivePlans = maxActivePlans;
@@ -684,23 +406,23 @@
}
public void setMaxReserveKB(int maxReserveBatchKB) {
- this.maxReserveKB = maxReserveBatchKB;
+ this.maxReserveKB.set(maxReserveBatchKB);
}
@Override
public void initialize() throws TeiidComponentException {
int maxMemory = (int)Math.min(Runtime.getRuntime().maxMemory() / 1024, Integer.MAX_VALUE);
maxMemory -= 300 * 1024; //assume 300 megs of overhead for the AS/system stuff
- if (maxReserveKB < 0) {
- this.maxReserveKB = 0;
+ if (getMaxReserveKB() < 0) {
+ this.setMaxReserveKB(0);
int one_gig = 1024 * 1024;
if (maxMemory > one_gig) {
//assume 75% of the memory over the first gig
- this.maxReserveKB += (int)Math.max(0, (maxMemory - one_gig) * .75);
+ this.maxReserveKB.addAndGet(((int)Math.max(0, (maxMemory - one_gig) * .75)));
}
- this.maxReserveKB += Math.max(0, Math.min(one_gig, maxMemory) * .5);
+ this.maxReserveKB.addAndGet(((int)Math.max(0, Math.min(one_gig, maxMemory) * .5)));
}
- this.reserveBatchKB = this.maxReserveKB;
+ this.reserveBatchKB = this.getMaxReserveKB();
if (this.maxProcessingKBOrig == null) {
//store the config value so that we can be reinitialized (this is not a clean approach)
this.maxProcessingKBOrig = this.maxProcessingKB;
@@ -708,6 +430,11 @@
if (this.maxProcessingKBOrig < 0) {
this.maxProcessingKB = Math.max(Math.min(8 * processorBatchSize, Integer.MAX_VALUE), (int)(.1 * maxMemory)/maxActivePlans);
}
+ if (useWeakReferences) {
+ int memoryBatches = (this.maxProcessingKB * maxActivePlans + this.getMaxReserveKB()) / (processorBatchSize * targetBytesPerRow / 1024);
+ int logSize = 39 - Integer.numberOfLeadingZeros(memoryBatches);
+ weakReferenceCache = new WeakReferenceHashedValueCache<CacheEntry>(Math.min(20, logSize));
+ }
}
@Override
@@ -736,7 +463,7 @@
try {
if (mode == BufferReserveMode.WAIT) {
//don't wait for more than is available
- int waitCount = Math.min(count, this.maxReserveKB);
+ int waitCount = Math.min(count, this.getMaxReserveKB());
while (waitCount > 0 && waitCount > this.reserveBatchKB) {
try {
batchesFreed.await(100, TimeUnit.MILLISECONDS);
@@ -760,46 +487,186 @@
}
void persistBatchReferences() {
- if (activeBatchKB == 0 || activeBatchKB <= reserveBatchKB) {
- int memoryCount = activeBatchKB + maxReserveKB - reserveBatchKB;
+ if (activeBatchKB.get() == 0 || activeBatchKB.get() <= reserveBatchKB) {
+ int memoryCount = activeBatchKB.get() + getMaxReserveKB() - reserveBatchKB;
if (DataTypeManager.isValueCacheEnabled()) {
- if (memoryCount < maxReserveKB / 8) {
+ if (memoryCount < getMaxReserveKB() / 8) {
DataTypeManager.setValueCacheEnabled(false);
}
- } else if (memoryCount > maxReserveKB / 4) {
+ } else if (memoryCount > getMaxReserveKB() / 4) {
DataTypeManager.setValueCacheEnabled(true);
}
return;
}
+ boolean first = true;
while (true) {
- ManagedBatchImpl mb = null;
- synchronized (activeBatches) {
- if (activeBatchKB == 0 || activeBatchKB < reserveBatchKB * .8) {
+ CacheEntry ce = null;
+ synchronized (memoryEntries) {
+ if (activeBatchKB.get() == 0 || activeBatchKB.get() < reserveBatchKB * .8) {
break;
}
- Iterator<TupleBufferInfo> iter = activeBatches.values().iterator();
- TupleBufferInfo tbi = iter.next();
- Map.Entry<Long, ManagedBatchImpl> entry = null;
- if (tbi.lastUsed != null) {
- entry = tbi.batches.floorEntry(tbi.lastUsed - 1);
+ if (first) { //let one entry per persist cycle loose its tenure. this helps us be more write avoident.
+ first = false;
+ if (!tenuredMemoryEntries.isEmpty()) {
+ Iterator<Map.Entry<Long, CacheEntry>> iter = tenuredMemoryEntries.entrySet().iterator();
+ Map.Entry<Long, CacheEntry> entry = iter.next();
+ iter.remove();
+ memoryEntries.put(entry.getKey(), entry.getValue());
+ }
}
- if (entry == null) {
- entry = tbi.batches.lastEntry();
+ LinkedHashMap<Long, CacheEntry> toDrain = memoryEntries;
+ if (memoryEntries.isEmpty()) {
+ toDrain = tenuredMemoryEntries;
+ if (tenuredMemoryEntries.isEmpty()) {
+ break;
+ }
+ }
+ Iterator<CacheEntry> iter = toDrain.values().iterator();
+ ce = iter.next();
+ iter.remove();
+ activeBatchKB.addAndGet(-ce.getSizeEstimate());
+ }
+ persist(ce);
+ }
+ }
+
+ void persist(CacheEntry ce) {
+ Serializer<?> s = ce.getSerializer().get();
+ if (s == null) {
+ return;
+ }
+ if (!ce.isPersistent()) {
+ long count = writeCount.incrementAndGet();
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
+ LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, ce.getId(), "writing batch to storage, total writes: ", count); //$NON-NLS-1$
+ }
+ cache.add(ce, s);
+ ce.setPersistent(true);
+ }
+ if (s.useSoftCache()) {
+ createSoftReference(ce);
+ } else if (useWeakReferences) {
+ weakReferenceCache.getValue(ce); //a get will set the value
+ }
+ }
+
+ private void createSoftReference(CacheEntry ce) {
+ BatchSoftReference ref = new BatchSoftReference(ce, SOFT_QUEUE, ce.getSizeEstimate());
+ softCache.put(ce.getId(), ref);
+ maxReserveKB.addAndGet(- ce.getSizeEstimate()/2);
+ }
+
+ /**
+ * Get a CacheEntry without hitting the cache
+ */
+ CacheEntry fastGet(Long batch, boolean prefersMemory, boolean retain) {
+ CacheEntry ce = null;
+ synchronized (memoryEntries) {
+ if (retain) {
+ ce = tenuredMemoryEntries.get(batch);
+ if (ce == null) {
+ ce = memoryEntries.remove(batch);
+ if (ce != null) {
+ tenuredMemoryEntries.put(batch, ce);
+ }
}
- tbi.removeBatch(entry.getKey());
- if (tbi.batches.isEmpty()) {
- iter.remove();
+ } else {
+ ce = tenuredMemoryEntries.remove(batch);
+ if (ce == null) {
+ ce = memoryEntries.remove(batch);
}
- mb = entry.getValue();
}
- try {
- mb.persist();
- } catch (TeiidComponentException e) {
- LogManager.logError(LogConstants.CTX_BUFFER_MGR, e, "Error persisting batch, attempts to read that batch later will result in an exception"); //$NON-NLS-1$
+ }
+ if (ce != null) {
+ if (!retain) {
+ BufferManagerImpl.this.remove(ce, true);
}
+ return ce;
}
+ if (prefersMemory) {
+ BatchSoftReference bsr = softCache.get(batch);
+ if (bsr != null) {
+ ce = bsr.get();
+ if (ce != null) {
+ softCache.remove(batch);
+ maxReserveKB.addAndGet(bsr.sizeEstimate/2);
+ }
+ }
+ } else if (useWeakReferences) {
+ ce = weakReferenceCache.getByHash(batch);
+ if (ce == null || !ce.getId().equals(batch)) {
+ return null;
+ }
+ }
+ if (ce != null && ce.getObject() != null) {
+ referenceHit.getAndIncrement();
+ if (retain) {
+ addMemoryEntry(ce);
+ } else {
+ BufferManagerImpl.this.remove(ce, false);
+ }
+ return ce;
+ }
+ return null;
}
+ void remove(Long gid, Long batch, boolean prefersMemory) {
+ CacheEntry ce = fastGet(batch, prefersMemory, false);
+ if (ce == null) {
+ cache.remove(gid, batch);
+ } else {
+ ce.nullOut();
+ }
+ }
+
+ private void remove(CacheEntry ce, boolean inMemory) {
+ if (inMemory) {
+ activeBatchKB.addAndGet(-ce.getSizeEstimate());
+ }
+ Serializer<?> s = ce.getSerializer().get();
+ if (s != null) {
+ cache.remove(s.getId(), ce.getId());
+ }
+ }
+
+ Long addCacheEntry(CacheEntry ce, Serializer<?> s) {
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
+ LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "Add batch to BufferManager", ce.getId(), "with size estimate", ce.getSizeEstimate()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ cache.addToCacheGroup(s.getId(), ce.getId());
+ addMemoryEntry(ce);
+ return ce.getId();
+ }
+
+ void addMemoryEntry(CacheEntry ce) {
+ persistBatchReferences();
+ synchronized (memoryEntries) {
+ memoryEntries.put(ce.getId(), ce);
+ }
+ activeBatchKB.getAndAdd(ce.getSizeEstimate());
+ }
+
+ void removeCacheGroup(Long id, boolean prefersMemory) {
+ cleanSoftReferences();
+ Collection<Long> vals = cache.removeCacheGroup(id);
+ for (Long val : vals) {
+ fastGet(val, prefersMemory, false);
+ }
+ }
+
+ void cleanSoftReferences() {
+ for (int i = 0; i < 10; i++) {
+ BatchSoftReference ref = (BatchSoftReference)SOFT_QUEUE.poll();
+ if (ref == null) {
+ break;
+ }
+ softCache.remove(ref.key);
+ maxReserveKB.addAndGet(ref.sizeEstimate/2);
+ ref.sizeEstimate = 0;
+ ref.clear();
+ }
+ }
+
@Override
public int getProcessorBatchSize(List<? extends Expression> schema) {
return getSizeEstimates(schema)[0];
@@ -821,9 +688,9 @@
boolean less = totalCopy < targetBytesPerRow;
int rowCount = processorBatchSize;
- for (int i = 0; i < 2; i++) {
+ for (int i = 0; i < 3; i++) {
if (less) {
- totalCopy <<= 2;
+ totalCopy <<= 1;
} else {
totalCopy >>= 2;
}
@@ -891,9 +758,13 @@
public void setInlineLobs(boolean inlineLobs) {
this.inlineLobs = inlineLobs;
}
+
+ private int getMaxReserveKB() {
+ return maxReserveKB.get();
+ }
- public void setCompactionThreshold(int compactionThreshold) {
- this.compactionThreshold = compactionThreshold;
+ public void setCache(Cache cache) {
+ this.cache = cache;
}
}
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStorageManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStorageManager.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStorageManager.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -100,60 +100,72 @@
this.name = name;
}
- public synchronized int readDirect(long fileOffset, byte[] b, int offSet, int length) throws TeiidComponentException {
- try {
- RandomAccessFile fileAccess = fileInfo.open();
- fileAccess.seek(fileOffset);
- return fileAccess.read(b, offSet, length);
- } catch (IOException e) {
- throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", fileInfo.file.getAbsoluteFile())); //$NON-NLS-1$
- } finally {
- fileInfo.close();
- }
+ @Override
+ public synchronized long getLength() {
+ if (fileInfo == null) {
+ return 0;
+ }
+ return fileInfo.file.length();
}
-
- /**
- * Concurrent writes are prevented by FileStore, but in general should not happen since processing is single threaded.
- */
- public void writeDirect(long fileOffset, byte[] bytes, int offset, int length) throws TeiidComponentException {
- long used = usedBufferSpace.addAndGet(length);
- if (used > maxBufferSpace) {
- usedBufferSpace.addAndGet(-length);
- //TODO: trigger a compaction before this is thrown
- throw new TeiidComponentException(QueryPlugin.Util.getString("FileStoreageManager.space_exhausted", maxBufferSpace)); //$NON-NLS-1$
- }
+
+ @Override
+ protected synchronized int readWrite(long fileOffset, byte[] b, int offSet,
+ int length, boolean write) throws IOException {
+ if (!write) {
+ try {
+ RandomAccessFile fileAccess = fileInfo.open();
+ fileAccess.seek(fileOffset);
+ return fileAccess.read(b, offSet, length);
+ } finally {
+ fileInfo.close();
+ }
+ }
if (fileInfo == null) {
fileInfo = new FileInfo(createFile(name));
}
+ long bytesUsed = 0;
try {
RandomAccessFile fileAccess = fileInfo.open();
- fileAccess.setLength(fileOffset + length);
+ long newLength = fileOffset + length;
+ bytesUsed = newLength - fileAccess.length();
+ if (bytesUsed > 0) {
+ long used = usedBufferSpace.addAndGet(bytesUsed);
+ if (used > maxBufferSpace) {
+ usedBufferSpace.addAndGet(-bytesUsed);
+ //TODO: trigger a compaction before this is thrown
+ throw new IOException(QueryPlugin.Util.getString("FileStoreageManager.space_exhausted", maxBufferSpace)); //$NON-NLS-1$
+ }
+ fileAccess.setLength(bytesUsed);
+ bytesUsed = 0;
+ }
fileAccess.seek(fileOffset);
- fileAccess.write(bytes, offset, length);
- } catch(IOException e) {
- throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", fileInfo.file.getAbsoluteFile())); //$NON-NLS-1$
+ fileAccess.write(b, offSet, length);
} finally {
+ if (bytesUsed > 0) {
+ usedBufferSpace.addAndGet(-bytesUsed);
+ }
fileInfo.close();
- }
- }
+ }
+ return length;
+ }
+
+ @Override
+ public synchronized void setLength(long length) throws IOException {
+ try {
+ fileInfo.open().setLength(length);
+ } finally {
+ fileInfo.close();
+ }
+ }
- public void removeDirect() {
- usedBufferSpace.addAndGet(-len);
+ @Override
+ public synchronized void removeDirect() {
+ usedBufferSpace.addAndGet(-getLength());
if (fileInfo != null){
fileInfo.delete();
}
}
- @Override
- protected void truncateDirect(long length) throws TeiidComponentException {
- try {
- RandomAccessFile raf = fileInfo.open();
- raf.setLength(length);
- } catch (IOException e) {
- throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", fileInfo.file.getAbsoluteFile())); //$NON-NLS-1$
- }
- }
-
}
// Initialization
@@ -204,16 +216,12 @@
this.directory = directory;
}
- File createFile(String name) throws TeiidComponentException {
- try {
- File storageFile = File.createTempFile(FILE_PREFIX + name + "_", null, this.dirFile); //$NON-NLS-1$
- if (LogManager.isMessageToBeRecorded(org.teiid.logging.LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
- LogManager.logDetail(org.teiid.logging.LogConstants.CTX_BUFFER_MGR, "Created temporary storage area file " + storageFile.getAbsoluteFile()); //$NON-NLS-1$
- }
- return storageFile;
- } catch(IOException e) {
- throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_creating", name)); //$NON-NLS-1$
+ File createFile(String name) throws IOException {
+ File storageFile = File.createTempFile(FILE_PREFIX + name + "_", null, this.dirFile); //$NON-NLS-1$
+ if (LogManager.isMessageToBeRecorded(org.teiid.logging.LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
+ LogManager.logDetail(org.teiid.logging.LogConstants.CTX_BUFFER_MGR, "Created temporary storage area file " + storageFile.getAbsoluteFile()); //$NON-NLS-1$
}
+ return storageFile;
}
public FileStore createFileStore(String name) {
Added: trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStoreCache.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStoreCache.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStoreCache.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -0,0 +1,417 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.teiid.common.buffer.Cache;
+import org.teiid.common.buffer.CacheEntry;
+import org.teiid.common.buffer.FileStore;
+import org.teiid.common.buffer.Serializer;
+import org.teiid.common.buffer.StorageManager;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidRuntimeException;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
+import org.teiid.logging.MessageLevel;
+import org.teiid.query.QueryPlugin;
+
+/**
+ * Implements storage and caching against a {@link FileStore} abstraction.
+ * caching uses a block paradigm, where the first block has the format
+ * long gid | long oid | short tail bytes | short sector table length | [3 byte int sector ...]
+ *
+ * TODO: back non-fragmented block information onto the block address
+ */
+public class FileStoreCache implements Cache, StorageManager {
+
+ private static final int IO_BUFFER_SIZE = 1 << 14;
+ private static final int DATA_START = 1 << 13;
+ private static final int MAX_BLOCKS = 2724; //implies that the max size is ~ 42.5 mb
+
+ static class TryFreeParameter {
+ Long gid;
+ Long oid;
+ Integer block;
+
+ public TryFreeParameter(Long gid, Long oid, Integer block) {
+ this.gid = gid;
+ this.oid = oid;
+ this.block = block;
+ }
+ }
+
+ private class Segment {
+ int id;
+ ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+ List<TryFreeParameter> freed = Collections.synchronizedList(new ArrayList<TryFreeParameter>());
+ FileStore store;
+ BitSetTree inuse = new BitSetTree();
+ BitSetTree fragmentedFlags = new BitSetTree();
+
+ public Segment(int id) {
+ this.id = id;
+ }
+
+ void tryFree(Long gid, Long oid, Integer block) {
+ if (lock.writeLock().tryLock()) {
+ try {
+ free(gid, oid, block);
+ } finally {
+ lock.writeLock().unlock();
+ }
+ } else {
+ freed.add(new TryFreeParameter(gid, oid, block));
+ }
+ }
+
+ private void free(Long gid, Long oid, Integer block) {
+ if (block == null) {
+ Map<Long, Integer> map = physicalMapping.get(gid);
+ if (map == null) {
+ return;
+ }
+ block = map.remove(oid);
+ if (block == null) {
+ return;
+ }
+ }
+ byte[] buf = new byte[DATA_START];
+ try {
+ inuse.set(block, false);
+ boolean fragmented = false;
+ if (fragmentedFlags.get(block)) {
+ fragmented = true;
+ store.read(block << 14, buf, 0, buf.length);
+ fragmentedFlags.set(block, false);
+ } else {
+ //TODO: if not fragmented come up with a better approach than a disk read
+ store.read(block << 14, buf, 0, 20);
+ }
+ ByteBuffer bb = ByteBuffer.wrap(buf);
+ bb.position(18);
+ short blocks = bb.getShort();
+ if (!fragmented) {
+ for (int i = block + 1; i < blocks; i++) {
+ inuse.set(i, false);
+ }
+ } else {
+ for (short i = 0; i < blocks; i++) {
+ int toFree = getNextBlock(bb);
+ inuse.set(toFree, false);
+ }
+ }
+ } catch (IOException e) {
+ throw new TeiidRuntimeException(e, "Could not read intial block to process freeing " + oid); //$NON-NLS-1$
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ void add(final CacheEntry entry, final Serializer s) throws TeiidComponentException {
+ lock.writeLock().lock();
+ try {
+ List<TryFreeParameter> toFree = Collections.emptyList();
+ synchronized (freed) {
+ if (!freed.isEmpty()) {
+ toFree = new ArrayList<TryFreeParameter>(freed);
+ freed.clear();
+ }
+ }
+ for (TryFreeParameter param : toFree) {
+ free(param.gid, param.oid, param.block);
+ }
+ ExtensibleBufferedOutputStream fsos = new ExtensibleBufferedOutputStream(new byte[IO_BUFFER_SIZE]) {
+
+ byte[] firstBytes = null;
+ List<Integer> blocks = new ArrayList<Integer>(8);
+ boolean isFragmented;
+ int lastCount;
+ int start;
+
+ @Override
+ protected void flushDirect() throws IOException {
+ lastCount = count;
+ if (firstBytes == null) {
+ start = nextBlock(-1);
+ firstBytes = buf;
+ //need a new buffer only if there could be bytes remaining
+ if (count == buf.length) {
+ buf = new byte[IO_BUFFER_SIZE];
+ }
+ } else {
+ int last = -1;
+ if (!blocks.isEmpty()) {
+ last = blocks.get(blocks.size()-1);
+ } else {
+ last = start;
+ }
+ int next = nextBlock(last);
+ blocks.add(next);
+ if (next != last + 1) {
+ isFragmented = true;
+ }
+ if (blocks.size() > MAX_BLOCKS) {
+ //TODO handle this case
+ throw new TeiidRuntimeException("Exceeded max persistent object size" + entry.getId()); //$NON-NLS-1$
+ }
+ store.write(next << 14, buf, 0, count);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ super.close();
+ ByteBuffer bb = ByteBuffer.wrap(firstBytes);
+ bb.putLong(s.getId());
+ bb.putLong(entry.getId());
+ bb.putShort((short)(lastCount - (blocks.isEmpty()?DATA_START:0)));
+ bb.putShort((short)blocks.size());
+ for (Integer i : blocks) {
+ bb.put((byte)(i.intValue()>>16));
+ bb.putShort((short)i.intValue());
+ }
+ store.write(start << 14, firstBytes, 0, firstBytes.length);
+ if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
+ LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, id, entry.getId(), "batch written starting at:", start); //$NON-NLS-1$
+ }
+ Map<Long, Integer> map = physicalMapping.get(s.getId());
+ if (map == null) {
+ return;
+ }
+ map.put(entry.getId(), start);
+ inuse.set(start, true);
+ for (Integer i : blocks) {
+ inuse.set(i, true);
+ }
+ if (isFragmented) {
+ fragmentedFlags.set(start, true);
+ }
+ }
+
+ };
+ fsos.count = DATA_START;
+ ObjectOutputStream oos = new ObjectOutputStream(fsos);
+ oos.writeInt(entry.getSizeEstimate());
+ s.serialize(entry.getObject(), oos);
+ oos.close();
+ } catch (IOException e) {
+ throw new TeiidComponentException(e);
+ } finally {
+ lock.writeLock().unlock();
+ }
+
+ if (entry.getId().longValue() == 451) {
+ get(entry.getId(), s);
+ }
+ }
+
+ int nextBlock(int fromIndex) {
+ int next = inuse.nextClearBit(fromIndex + 1);
+ if (next == -1) {
+ throw new TeiidRuntimeException("no freespace available on segment" + id); //$NON-NLS-1$
+ }
+ return next;
+ }
+
+ @SuppressWarnings("unchecked")
+ CacheEntry get(Long oid, Serializer serializer) throws TeiidComponentException {
+ lock.readLock().lock();
+ try {
+ Map<Long, Integer> map = physicalMapping.get(serializer.getId());
+ if (map == null) {
+ return null;
+ }
+ final Integer startBlock = map.get(oid);
+ if (startBlock == null) {
+ return null;
+ }
+ ObjectInputStream ois = new ObjectInputStream(new InputStream() {
+
+ int count;
+ int pos;
+ byte[] buf = new byte[IO_BUFFER_SIZE];
+ ByteBuffer firstBytes;
+ int currentBlock;
+ short tailBytes;
+ short totalBlocks;
+ short blockNum;
+
+ @Override
+ public int read() throws IOException {
+ if (pos == count) {
+ if (firstBytes == null) {
+ store.readFully(startBlock << 14, buf, 0, buf.length);
+ firstBytes = ByteBuffer.wrap(buf);
+ firstBytes.position(16);
+ tailBytes = firstBytes.getShort();
+ totalBlocks = firstBytes.getShort();
+ count = buf.length;
+ pos = DATA_START;
+ } else {
+ buf = new byte[IO_BUFFER_SIZE];
+ //TODO: defrag on read
+ if (count == buf.length) {
+ currentBlock = getNextBlock(firstBytes);
+ blockNum++;
+ pos = 0;
+ }
+ int length = blockNum == totalBlocks?tailBytes:buf.length;
+ store.readFully(currentBlock << 14, buf, 0, length);
+ count = length;
+ }
+ }
+ return buf[pos++] & 0xff;
+ }
+ });
+ CacheEntry ce = new CacheEntry(oid);
+ ce.setSizeEstimate(ois.readInt());
+ ce.setObject(serializer.deserialize(ois));
+ ce.setPersistent(true);
+ return ce;
+ } catch(IOException e) {
+ throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", id)); //$NON-NLS-1$
+ } catch (ClassNotFoundException e) {
+ throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", id)); //$NON-NLS-1$
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+ }
+
+ static int getNextBlock(ByteBuffer bb) {
+ int block = (bb.get() & 0xff)<< 16;
+ block += (bb.getShort() & 0xffff);
+ return block;
+ }
+
+ private StorageManager storageManager;
+ private Segment[] segments;
+ private ConcurrentHashMap<Long, Map<Long, Integer>> physicalMapping = new ConcurrentHashMap<Long, Map<Long,Integer>>();
+ private int segmentCount = 32;
+
+ @Override
+ public void add(CacheEntry entry, Serializer<?> s) {
+ Segment seg = getSegment(entry.getId());
+ try {
+ seg.add(entry, s);
+ } catch (Throwable e) {
+ LogManager.logError(LogConstants.CTX_BUFFER_MGR, e, "Error persisting batch, attempts to read batch "+ entry.getId() +" later will result in an exception"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ @Override
+ public CacheEntry get(Long id, Serializer<?> serializer) throws TeiidComponentException {
+ Segment seg = getSegment(id);
+ return seg.get(id, serializer);
+ }
+
+ private Segment getSegment(Long id) {
+ return segments[id.hashCode() & (segments.length - 1)];
+ }
+
+ @Override
+ public FileStore createFileStore(String name) {
+ return storageManager.createFileStore(name);
+ }
+
+ @Override
+ public void initialize() throws TeiidComponentException {
+ storageManager.initialize();
+ int numSegments = 31 - Integer.numberOfLeadingZeros(this.segmentCount);
+ segments = new Segment[1 << numSegments];
+ for (int i = 0; i < segments.length; i++) {
+ segments[i] = new Segment(i);
+ segments[i].store = storageManager.createFileStore("segment_" + i); //$NON-NLS-1$
+ }
+ }
+
+ @Override
+ public void addToCacheGroup(Long gid, Long oid) {
+ Map<Long, Integer> map = physicalMapping.get(gid);
+ if (map == null) {
+ return;
+ }
+ map.put(oid, null);
+ }
+
+ @Override
+ public void createCacheGroup(Long gid) {
+ physicalMapping.put(gid, Collections.synchronizedMap(new HashMap<Long, Integer>()));
+ }
+
+ @Override
+ public void remove(Long gid, Long id) {
+ Map<Long, Integer> map = physicalMapping.get(gid);
+ if (map == null) {
+ return;
+ }
+ Integer block = map.remove(id);
+ if (block != null) {
+ Segment s = getSegment(id);
+ s.tryFree(gid, id, block);
+ }
+ }
+
+ @Override
+ public Collection<Long> removeCacheGroup(Long gid) {
+ Map<Long, Integer> values = physicalMapping.remove(gid);
+ if (values == null) {
+ return Collections.emptySet();
+ }
+ synchronized (values) {
+ for (Map.Entry<Long, Integer> entry : values.entrySet()) {
+ if (entry.getValue() != null) {
+ Segment s = getSegment(entry.getKey());
+ s.tryFree(gid, entry.getKey(), entry.getValue());
+ }
+ }
+ return new HashSet<Long>(values.keySet());
+ }
+ }
+
+ public void setSegmentCount(int segmentCount) {
+ this.segmentCount = segmentCount;
+ }
+
+ public void setStorageManager(StorageManager storageManager) {
+ this.storageManager = storageManager;
+ }
+
+ public StorageManager getStorageManager() {
+ return storageManager;
+ }
+
+}
Property changes on: trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStoreCache.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/MemoryStorageManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/MemoryStorageManager.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/MemoryStorageManager.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -23,70 +23,85 @@
package org.teiid.common.buffer.impl;
import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
+import org.teiid.common.buffer.Cache;
+import org.teiid.common.buffer.CacheEntry;
import org.teiid.common.buffer.FileStore;
-import org.teiid.common.buffer.StorageManager;
+import org.teiid.common.buffer.Serializer;
import org.teiid.core.TeiidComponentException;
-public class MemoryStorageManager implements StorageManager {
+public class MemoryStorageManager implements Cache {
+
+ public static final int MAX_FILE_SIZE = 1 << 17;
- private AtomicInteger created = new AtomicInteger();
- private AtomicInteger removed = new AtomicInteger();
-
- public void initialize() {
- }
+ private final class MemoryFileStore extends FileStore {
+ private ByteBuffer buffer = ByteBuffer.allocate(MAX_FILE_SIZE);
+
+ public MemoryFileStore() {
+ buffer.limit(0);
+ }
- @Override
- public FileStore createFileStore(String name) {
- created.incrementAndGet();
- return new FileStore() {
- private ByteBuffer buffer = ByteBuffer.allocate(1 << 16);
-
- @Override
- public void writeDirect(long start, byte[] bytes, int offset, int length) throws TeiidComponentException {
- buffer.position((int)start);
- if (buffer.position() + length > buffer.capacity()) {
- ByteBuffer newBuffer = ByteBuffer.allocate(buffer.capacity() * 2 + length);
- buffer.position(0);
- newBuffer.put(buffer);
- buffer = newBuffer;
- buffer.position((int)start);
- }
- buffer.put(bytes, offset, length);
- }
-
- @Override
- public void removeDirect() {
- removed.incrementAndGet();
- buffer = ByteBuffer.allocate(0);
- }
-
- @Override
- public synchronized int readDirect(long fileOffset, byte[] b, int offset, int length)
- throws TeiidComponentException {
+ @Override
+ public synchronized void removeDirect() {
+ removed.incrementAndGet();
+ buffer = ByteBuffer.allocate(0);
+ }
+
+ @Override
+ protected synchronized int readWrite(long fileOffset, byte[] b, int offSet,
+ int length, boolean write) {
+ if (!write) {
if (fileOffset >= getLength()) {
return -1;
}
int position = (int)fileOffset;
buffer.position(position);
length = Math.min(length, (int)getLength() - position);
- buffer.get(b, offset, length);
- return length;
+ buffer.get(b, offSet, length);
+ return length;
}
-
- @Override
- protected void truncateDirect(long length) {
- ByteBuffer newBuffer = ByteBuffer.allocate((int)length);
- buffer.position(0);
- buffer.limit(newBuffer.capacity());
- newBuffer.put(buffer);
- buffer = newBuffer;
+ int requiredLength = (int)(fileOffset + length);
+ if (requiredLength > buffer.limit()) {
+ buffer.limit(requiredLength);
}
- };
+ buffer.position((int)fileOffset);
+ buffer.put(b, offSet, length);
+ return length;
+ }
+
+ @Override
+ public synchronized void setLength(long length) {
+ buffer.limit((int)length);
+ }
+
+ @Override
+ public synchronized long getLength() {
+ return buffer.limit();
+ }
+
}
+
+ private Map<Long, Map<Long, CacheEntry>> groups = new ConcurrentHashMap<Long, Map<Long, CacheEntry>>();
+ private AtomicInteger created = new AtomicInteger();
+ private AtomicInteger removed = new AtomicInteger();
+ public void initialize() {
+ }
+
+ @Override
+ public FileStore createFileStore(String name) {
+ created.incrementAndGet();
+ return new MemoryFileStore();
+ }
+
public int getCreated() {
return created.get();
}
@@ -94,4 +109,55 @@
public int getRemoved() {
return removed.get();
}
+
+ @Override
+ public void add(CacheEntry entry, Serializer<?> s) {
+ Map<Long, CacheEntry> group = groups.get(s.getId());
+ if (group != null) {
+ group.put(entry.getId(), entry);
+ }
+ }
+
+ @Override
+ public void addToCacheGroup(Long gid, Long oid) {
+ Map<Long, CacheEntry> group = groups.get(gid);
+ if (group != null) {
+ group.put(oid, null);
+ }
+ }
+
+ @Override
+ public void createCacheGroup(Long gid) {
+ groups.put(gid, Collections.synchronizedMap(new HashMap<Long, CacheEntry>()));
+ }
+
+ @Override
+ public CacheEntry get(Long id, Serializer<?> serializer)
+ throws TeiidComponentException {
+ Map<Long, CacheEntry> group = groups.get(id);
+ if (group != null) {
+ return group.get(id);
+ }
+ return null;
+ }
+
+ @Override
+ public void remove(Long gid, Long id) {
+ Map<Long, CacheEntry> group = groups.get(gid);
+ if (group != null) {
+ group.remove(id);
+ }
+ }
+
+ @Override
+ public Collection<Long> removeCacheGroup(Long gid) {
+ Map<Long, CacheEntry> group = groups.remove(gid);
+ if (group == null) {
+ return Collections.emptySet();
+ }
+ synchronized (group) {
+ return new ArrayList<Long>(group.keySet());
+ }
+ }
+
}
\ No newline at end of file
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/SizeUtility.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/SizeUtility.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/SizeUtility.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -26,9 +26,9 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
-import org.teiid.common.buffer.TupleBatch;
import org.teiid.core.types.DataTypeManager;
@@ -65,27 +65,29 @@
private long bigIntegerEstimate;
private long bigDecimalEstimate;
+ private String[] types;
- public SizeUtility() {
+ public SizeUtility(String[] types) {
boolean isValueCacheEnabled = DataTypeManager.isValueCacheEnabled();
bigIntegerEstimate = getSize(isValueCacheEnabled, DataTypeManager.DefaultDataClasses.BIG_INTEGER);
bigDecimalEstimate = getSize(isValueCacheEnabled, DataTypeManager.DefaultDataClasses.BIG_DECIMAL);
+ this.types = types;
}
- public long getBatchSize(TupleBatch data) {
+ public long getBatchSize(List<? extends List<?>> data) {
return getBatchSize(DataTypeManager.isValueCacheEnabled(), data);
}
- private long getBatchSize(boolean accountForValueCache, TupleBatch data) {
- int colLength = data.getDataTypes().length;
- int rowLength = data.getRowCount();
+ private long getBatchSize(boolean accountForValueCache, List<? extends List<?>> data) {
+ int colLength = types.length;
+ int rowLength = data.size();
// Array overhead for row array
long size = 16 + alignMemory(rowLength * REFERENCE_SIZE);
// array overhead for all the columns ( 8 object overhead + 4 ref + 4 int)
size += (rowLength * (48 + alignMemory(colLength * REFERENCE_SIZE)));
for (int col = 0; col < colLength; col++) {
- Class<?> type = DataTypeManager.getDataTypeClass(data.getDataTypes()[col]);
+ Class<?> type = DataTypeManager.getDataTypeClass(types[col]);
if (type == DataTypeManager.DefaultDataClasses.STRING
|| type == DataTypeManager.DefaultDataClasses.OBJECT
@@ -94,7 +96,7 @@
int estRow = 0;
for (int row = 0; row < rowLength; row++) {
boolean updateEst = row == estRow;
- size += getSize(data.getTuples().get(row).get(col), updateEst, accountForValueCache);
+ size += getSize(data.get(row).get(col), updateEst, accountForValueCache);
if (updateEst) {
estRow = estRow * 2 + 1;
}
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -22,9 +22,9 @@
package org.teiid.common.buffer.impl;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.concurrent.ConcurrentSkipListMap;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import org.teiid.common.buffer.FileStore;
import org.teiid.common.buffer.StorageManager;
@@ -32,8 +32,8 @@
public class SplittableStorageManager implements StorageManager {
- public static final long DEFAULT_MAX_FILESIZE = 2L * 1024L;
- private long maxFileSize = DEFAULT_MAX_FILESIZE * 1024L * 1024L; // 2GB
+ public static final long DEFAULT_MAX_FILESIZE = 2 * 1024l;
+ private long maxFileSize = DEFAULT_MAX_FILESIZE * 1024l * 1024l; // 2GB
private StorageManager storageManager;
public SplittableStorageManager(StorageManager storageManager) {
@@ -52,73 +52,93 @@
public class SplittableFileStore extends FileStore {
private String name;
- private ConcurrentSkipListMap<Long, FileStore> storageFiles = new ConcurrentSkipListMap<Long, FileStore>();
+ private List<FileStore> storageFiles = new ArrayList<FileStore>();
+
+ private volatile long len;
public SplittableFileStore(String name) {
this.name = name;
}
@Override
- public int readDirect(long fileOffset, byte[] b, int offSet, int length) throws TeiidComponentException {
- Map.Entry<Long, FileStore> entry = storageFiles.floorEntry(fileOffset);
- FileStore fileInfo = entry.getValue();
- return fileInfo.read(fileOffset - entry.getKey(), b, offSet, length);
+ public long getLength() {
+ return len;
}
+
+ @Override
+ protected int readWrite(long fileOffset, byte[] b, int offSet,
+ int length, boolean write) throws IOException {
+ FileStore store = null;
+ if (!write) {
+ synchronized (this) {
+ if (fileOffset + length > len) {
+ throw new IOException("Invalid file position " + fileOffset + " length " + length); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ store = storageFiles.get((int)(fileOffset/maxFileSize));
+ }
+ return store.read(fileOffset%maxFileSize, b, offSet, length);
+ }
+ synchronized (this) {
+ ensureLength(fileOffset + length);
+ store = storageFiles.get((int)(fileOffset/maxFileSize));
+ }
+ long fileBegin = (int)(fileOffset%maxFileSize);
+ length = Math.min(length, (int)Math.min(Integer.MAX_VALUE, maxFileSize - fileBegin));
+ store.write(fileBegin, b, offSet, length);
+ return length;
+ }
+ private void ensureLength(long length) throws IOException {
+ if (length <= len) {
+ return;
+ }
+ int numFiles = (int)(length/maxFileSize);
+ long lastFileSize = length%maxFileSize;
+ if (lastFileSize > 0) {
+ numFiles++;
+ }
+ for (int i = storageFiles.size(); i < numFiles; i++) {
+ FileStore newFileInfo = storageManager.createFileStore(name + "_" + storageFiles.size()); //$NON-NLS-1$
+ storageFiles.add(newFileInfo);
+ if (lastFileSize == 0 || i != numFiles - 1) {
+ newFileInfo.setLength(maxFileSize);
+ }
+ }
+ if (lastFileSize > 0) {
+ storageFiles.get(storageFiles.size() - 1).setLength(lastFileSize);
+ }
+ len = length;
+ }
+
@Override
- public void writeDirect(long start, byte[] bytes, int offset, int length) throws TeiidComponentException {
- Map.Entry<Long, FileStore> entry = this.storageFiles.floorEntry(start);
- boolean createNew = false;
- FileStore fileInfo = null;
- long fileOffset = 0;
- if (entry == null) {
- createNew = true;
+ public synchronized void setLength(long length) throws IOException {
+ if (length > len) {
+ ensureLength(length);
} else {
- fileInfo = entry.getValue();
- fileOffset = entry.getKey();
- if (start > entry.getValue().getLength() + fileOffset) {
- throw new AssertionError("invalid write start location"); //$NON-NLS-1$
+ int numFiles = (int)(length/maxFileSize);
+ long lastFileSize = length%maxFileSize;
+ if (lastFileSize > 0) {
+ numFiles++;
}
- createNew = start + length > getMaxFileSize();
+ int toRemove = storageFiles.size() - numFiles;
+ for (int i = 0; i < toRemove; i++) {
+ FileStore store = storageFiles.remove(storageFiles.size() -1);
+ store.remove();
+ }
+ if (lastFileSize > 0) {
+ storageFiles.get(storageFiles.size() - 1).setLength(lastFileSize);
+ }
}
- if (createNew) {
- FileStore newFileInfo = storageManager.createFileStore(name + "_" + storageFiles.size()); //$NON-NLS-1$
- if (fileInfo != null) {
- fileOffset += fileInfo.getLength();
- }
- storageFiles.put(fileOffset, newFileInfo);
- fileInfo = newFileInfo;
- }
- fileInfo.write(start - fileOffset, bytes, offset, length);
- }
-
- public void removeDirect() {
- for (FileStore info : storageFiles.values()) {
+ len = length;
+ }
+
+ public synchronized void removeDirect() {
+ for (FileStore info : storageFiles) {
info.remove();
}
storageFiles.clear();
}
- @Override
- protected void truncateDirect(long length)
- throws TeiidComponentException {
- Map.Entry<Long, FileStore> start = storageFiles.floorEntry(length);
- if (start == null) {
- return;
- }
- if (start.getKey().longValue() == length) {
- start.getValue().remove();
- storageFiles.remove(start.getKey());
- } else {
- start.getValue().truncate(length - start.getKey());
- }
- for (Iterator<FileStore> iter = storageFiles.tailMap(length, false).values().iterator(); iter.hasNext();) {
- iter.next().remove();
- iter.remove();
- }
-
- }
-
}
public long getMaxFileSize() {
@@ -126,10 +146,10 @@
}
public void setMaxFileSize(long maxFileSize) {
- this.maxFileSize = maxFileSize * 1024L * 1024L;
+ this.maxFileSize = maxFileSize * 1024l * 1024l;
}
- void setMaxFileSizeDirect(long maxFileSize) {
+ public void setMaxFileSizeDirect(long maxFileSize) {
this.maxFileSize = maxFileSize;
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -31,7 +31,6 @@
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.common.buffer.BlockedException;
-import org.teiid.common.buffer.TupleBuffer;
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.util.Assertion;
import org.teiid.dqp.message.AtomicRequestID;
@@ -332,7 +331,7 @@
LogManager.logWarning(LogConstants.CTX_CONNECTOR, QueryPlugin.Util.getString("ConnectorWorker.zero_size_non_last_batch", requestMsg.getConnectorName())); //$NON-NLS-1$
}
- AtomicResultsMessage response = createResultsMessage(rows.toArray(new List[currentRowCount]), requestMsg.getCommand().getProjectedSymbols());
+ AtomicResultsMessage response = createResultsMessage(rows.toArray(new List[currentRowCount]));
// if we need to keep the execution alive, then we can not support implicit close.
response.setSupportsImplicitClose(!this.securityContext.keepExecutionAlive());
@@ -346,9 +345,8 @@
return response;
}
- public static AtomicResultsMessage createResultsMessage(List[] batch, List columnSymbols) {
- String[] dataTypes = TupleBuffer.getTypeNames(columnSymbols);
- return new AtomicResultsMessage(batch, dataTypes);
+ public static AtomicResultsMessage createResultsMessage(List[] batch) {
+ return new AtomicResultsMessage(batch);
}
boolean isCancelled() {
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -398,7 +398,7 @@
fullyCloseSource();
}
if(workItem.requestMsg.supportsPartialResults()) {
- AtomicResultsMessage emptyResults = new AtomicResultsMessage(new List[0], null);
+ AtomicResultsMessage emptyResults = new AtomicResultsMessage(new List[0]);
emptyResults.setWarnings(Arrays.asList((Exception)exception));
emptyResults.setFinalRow(this.rowsProcessed);
return emptyResults;
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -25,12 +25,13 @@
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
-import java.util.concurrent.ConcurrentHashMap;
import org.teiid.client.RequestMessage;
import org.teiid.client.ResultsMessage;
@@ -144,7 +145,7 @@
* maintained during processing
*/
private Throwable processingException;
- private Map<AtomicRequestID, DataTierTupleSource> connectorInfo = new ConcurrentHashMap<AtomicRequestID, DataTierTupleSource>(4);
+ private Map<AtomicRequestID, DataTierTupleSource> connectorInfo = Collections.synchronizedMap(new HashMap<AtomicRequestID, DataTierTupleSource>(4));
// This exception contains details of all the atomic requests that failed when query is run in partial results mode.
private List<TeiidException> warnings = new LinkedList<TeiidException>();
private volatile boolean doneProducingBatches;
@@ -157,7 +158,7 @@
private int begin;
private int end;
private TupleBatch savedBatch;
- private Map<Integer, LobWorkItem> lobStreams = new ConcurrentHashMap<Integer, LobWorkItem>(4);
+ private Map<Integer, LobWorkItem> lobStreams = Collections.synchronizedMap(new HashMap<Integer, LobWorkItem>(4));
/**The time when command begins processing on the server.*/
private long processingTimestamp = System.currentTimeMillis();
@@ -362,7 +363,7 @@
* break the read of a lob from a transactional source under a transaction
* if the source does not support holding the clob open after commit
*/
- for (DataTierTupleSource connectorRequest : this.connectorInfo.values()) {
+ for (DataTierTupleSource connectorRequest : getConnectorRequests()) {
if (connectorRequest.isTransactional()) {
connectorRequest.fullyCloseSource();
}
@@ -401,15 +402,21 @@
}
}
- for (DataTierTupleSource connectorRequest : this.connectorInfo.values()) {
+ for (DataTierTupleSource connectorRequest : getConnectorRequests()) {
connectorRequest.fullyCloseSource();
}
}
this.resultsBuffer = null;
- for (LobWorkItem lobWorkItem : this.lobStreams.values()) {
- lobWorkItem.close();
+ if (!this.lobStreams.isEmpty()) {
+ List<LobWorkItem> lobs = null;
+ synchronized (lobStreams) {
+ lobs = new ArrayList<LobWorkItem>(this.lobStreams.values());
+ }
+ for (LobWorkItem lobWorkItem : lobs) {
+ lobWorkItem.close();
+ }
}
}
@@ -592,7 +599,7 @@
}
int finalRowCount = this.resultsBuffer.isFinal()?this.resultsBuffer.getRowCount():(batch.getTerminationFlag()?batch.getEndRow():-1);
- response = createResultsMessage(batch.getAllTuples(), this.originalCommand.getProjectedSymbols());
+ response = createResultsMessage(batch.getTuples(), this.originalCommand.getProjectedSymbols());
response.setFirstRow(batch.getBeginRow());
response.setLastRow(batch.getEndRow());
response.setUpdateResult(this.returnsUpdateCount);
@@ -631,7 +638,7 @@
return result;
}
- public ResultsMessage createResultsMessage(List[] batch, List columnSymbols) {
+ public ResultsMessage createResultsMessage(List<? extends List<?>> batch, List columnSymbols) {
String[] columnNames = new String[columnSymbols.size()];
String[] dataTypes = new String[columnSymbols.size()];
@@ -640,7 +647,7 @@
columnNames[i] = SingleElementSymbol.getShortName(symbol.getOutputName());
dataTypes[i] = DataTypeManager.getDataTypeName(symbol.getType());
}
- ResultsMessage result = new ResultsMessage(requestMsg, batch, columnNames, dataTypes);
+ ResultsMessage result = new ResultsMessage(batch, columnNames, dataTypes);
setAnalysisRecords(result);
return result;
}
@@ -672,7 +679,7 @@
}
}
LogManager.logDetail(LogConstants.CTX_DQP, processingException, "Sending error to client", requestID); //$NON-NLS-1$
- ResultsMessage response = new ResultsMessage(requestMsg);
+ ResultsMessage response = new ResultsMessage();
Throwable exception = this.processingException;
if (isCanceled) {
exception = addCancelCode(exception);
@@ -737,7 +744,7 @@
// Cancel Connector atomic requests
try {
- for (DataTierTupleSource connectorRequest : this.connectorInfo.values()) {
+ for (DataTierTupleSource connectorRequest : getConnectorRequests()) {
connectorRequest.cancelRequest();
}
} finally {
@@ -837,7 +844,9 @@
Collection<DataTierTupleSource> getConnectorRequests() {
- return new LinkedList<DataTierTupleSource>(this.connectorInfo.values());
+ synchronized (this.connectorInfo) {
+ return new ArrayList<DataTierTupleSource>(this.connectorInfo.values());
+ }
}
DataTierTupleSource getConnectorRequest(AtomicRequestID id) {
@@ -874,7 +883,7 @@
this.doneProducingBatches = true;
//TODO: we could perform more tracking to know what source lobs are in use
if (this.resultsBuffer.getLobCount() == 0) {
- for (DataTierTupleSource connectorRequest : this.connectorInfo.values()) {
+ for (DataTierTupleSource connectorRequest : getConnectorRequests()) {
connectorRequest.fullyCloseSource();
}
}
Added: trunk/engine/src/main/java/org/teiid/dqp/internal/process/SerializableTupleBatch.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/SerializableTupleBatch.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/SerializableTupleBatch.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.dqp.internal.process;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.List;
+
+import org.teiid.client.BatchSerializer;
+import org.teiid.common.buffer.TupleBatch;
+import org.teiid.core.util.ExternalizeUtil;
+
+public class SerializableTupleBatch extends TupleBatch implements Externalizable {
+
+ private String[] types;
+
+ public SerializableTupleBatch() {
+ //for Externalizable
+ }
+
+ public SerializableTupleBatch(TupleBatch batch, String[] types) {
+ super(batch.getBeginRow(), batch.getTuples());
+ this.types = types;
+ }
+
+ @Override
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ String[] types = ExternalizeUtil.readStringArray(in);
+ this.setRowOffset(in.readInt());
+ this.setTerminationFlag(in.readBoolean());
+ this.tuples = (List)BatchSerializer.readBatch(in, types);
+ }
+
+ @Override
+ public void writeExternal(ObjectOutput out) throws IOException {
+ ExternalizeUtil.writeArray(out, types);
+ out.writeInt(this.getBeginRow());
+ out.writeBoolean(this.getTerminationFlag());
+ BatchSerializer.writeBatch(out, types, this.getTuples());
+ }
+
+}
Property changes on: trunk/engine/src/main/java/org/teiid/dqp/internal/process/SerializableTupleBatch.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/dqp/message/AtomicResultsMessage.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/message/AtomicResultsMessage.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/main/java/org/teiid/dqp/message/AtomicResultsMessage.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -22,20 +22,12 @@
package org.teiid.dqp.message;
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import java.util.List;
-import org.teiid.client.BatchSerializer;
-import org.teiid.core.util.ExternalizeUtil;
+public class AtomicResultsMessage {
-public class AtomicResultsMessage implements Externalizable {
-
private List[] results;
- private String[] dataTypes;
// Final row index in complete result set, if known
private int finalRow = -1;
@@ -53,8 +45,7 @@
public AtomicResultsMessage() {
}
- public AtomicResultsMessage(List[] results, String[] dataTypes) {
- this.dataTypes = dataTypes;
+ public AtomicResultsMessage(List[] results) {
this.results = results;
}
@@ -86,26 +77,6 @@
return results;
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- dataTypes = ExternalizeUtil.readStringArray(in);
- results = BatchSerializer.readBatch(in, dataTypes);
- finalRow = in.readInt();
- supportsImplicitClose = in.readBoolean();
- warnings = (List<Exception>)in.readObject();
- isTransactional = in.readBoolean();
- supportsCloseWithLobs = in.readBoolean();
- }
-
- public void writeExternal(ObjectOutput out) throws IOException {
- ExternalizeUtil.writeArray(out, dataTypes);
- BatchSerializer.writeBatch(out, dataTypes, results);
- out.writeInt(finalRow);
- out.writeBoolean(supportsImplicitClose);
- out.writeObject(warnings);
- out.writeBoolean(isTransactional);
- out.writeBoolean(supportsCloseWithLobs);
- }
-
public boolean isTransactional() {
return isTransactional;
}
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/EnhancedSortMergeJoinStrategy.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/EnhancedSortMergeJoinStrategy.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/EnhancedSortMergeJoinStrategy.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -141,6 +141,7 @@
List<?> lastTuple = null;
boolean sortedDistinct = sorted && !state.isDistinct();
int sizeHint = index.getExpectedHeight(state.getTupleBuffer().getRowCount());
+ index.setBatchInsert(sorted);
outer: while (its.hasNext()) {
//detect if sorted and distinct
List<?> originalTuple = its.nextTuple();
@@ -162,6 +163,8 @@
}
if (!sorted) {
index.compact();
+ } else {
+ index.setBatchInsert(false);
}
its.closeSource();
this.reverseIndexes = new int[elements.size()];
Modified: trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -90,6 +90,19 @@
this.addRowId = addRowId;
this.indexes = indexes;
}
+
+ @Override
+ int process() throws ExpressionEvaluationException,
+ TeiidComponentException, TeiidProcessingException {
+ tree.setBatchInsert(addRowId);
+ return super.process();
+ }
+
+ @Override
+ protected void afterCompletion() throws TeiidComponentException {
+ tree.setBatchInsert(false);
+ }
+
@Override
protected void tuplePassed(List tuple) throws BlockedException,
@@ -237,6 +250,7 @@
success = true;
} finally {
try {
+ afterCompletion();
if (!success && undoLog != null) {
undoLog.setFinal(true);
TupleSource undoTs = undoLog.createIndexedTupleSource();
@@ -260,6 +274,14 @@
return updateCount;
}
+ /**
+ *
+ * @throws TeiidComponentException
+ */
+ protected void afterCompletion() throws TeiidComponentException {
+
+ }
+
@SuppressWarnings("unused")
void success() throws TeiidComponentException, ExpressionEvaluationException, TeiidProcessingException {}
Modified: trunk/engine/src/test/java/org/teiid/common/buffer/BufferManagerFactory.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/BufferManagerFactory.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/BufferManagerFactory.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -22,9 +22,10 @@
package org.teiid.common.buffer;
-import org.teiid.common.buffer.BufferManager;
import org.teiid.common.buffer.impl.BufferManagerImpl;
+import org.teiid.common.buffer.impl.FileStoreCache;
import org.teiid.common.buffer.impl.MemoryStorageManager;
+import org.teiid.common.buffer.impl.SplittableStorageManager;
import org.teiid.core.TeiidComponentException;
@@ -81,12 +82,18 @@
public static BufferManagerImpl initBufferManager(BufferManagerImpl bufferManager) {
try {
bufferManager.initialize();
- } catch (TeiidComponentException e) {
+ MemoryStorageManager storageManager = new MemoryStorageManager();
+ SplittableStorageManager ssm = new SplittableStorageManager(storageManager);
+ ssm.setMaxFileSizeDirect(MemoryStorageManager.MAX_FILE_SIZE);
+ FileStoreCache fsc = new FileStoreCache();
+ fsc.setSegmentCount(1);
+ fsc.setStorageManager(ssm);
+ fsc.initialize();
+ bufferManager.setCache(fsc);
+ return bufferManager;
+ } catch (TeiidComponentException e) {
throw new RuntimeException(e);
}
-
- bufferManager.setStorageManager(new MemoryStorageManager());
- return bufferManager;
}
}
Modified: trunk/engine/src/test/java/org/teiid/common/buffer/TestLobManager.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/TestLobManager.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/TestLobManager.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -28,8 +28,10 @@
import java.io.StringReader;
import java.nio.charset.Charset;
import java.util.Arrays;
+import java.util.List;
import org.junit.Test;
+import org.teiid.common.buffer.LobManager.ReferenceMode;
import org.teiid.common.buffer.impl.BufferManagerImpl;
import org.teiid.core.types.BlobImpl;
import org.teiid.core.types.BlobType;
@@ -65,10 +67,11 @@
}));
- LobManager lobManager = new LobManager();
+ LobManager lobManager = new LobManager(new int[] {0, 1}, fs);
lobManager.setMaxMemoryBytes(4);
- lobManager.updateReferences(new int[] {0,1}, Arrays.asList(clob, blob));
- lobManager.persist(fs);
+ List<Streamable<? extends Object>> tuple = Arrays.asList(clob, blob);
+ lobManager.updateReferences(tuple, ReferenceMode.CREATE);
+ lobManager.persist();
Streamable<?>lob = lobManager.getLobReference(clob.getReferenceStreamId());
assertTrue(lob.getClass().isAssignableFrom(ClobType.class));
@@ -81,6 +84,10 @@
BlobType blobRead = (BlobType)lob;
assertTrue(Arrays.equals(ObjectConverterUtil.convertToByteArray(blob.getBinaryStream()), ObjectConverterUtil.convertToByteArray(blobRead.getBinaryStream())));
+ lobManager.updateReferences(tuple, ReferenceMode.REMOVE);
+
+ assertEquals(0, lobManager.getLobCount());
+
}
}
Modified: trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -109,7 +109,6 @@
BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
bm.setProcessorBatchSize(32);
bm.setMaxReserveKB(0);//force all to disk
- bm.setCompactionThreshold(0);
bm.initialize();
ElementSymbol e1 = new ElementSymbol("x");
Modified: trunk/engine/src/test/java/org/teiid/common/buffer/TestTupleBuffer.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/TestTupleBuffer.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/TestTupleBuffer.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -30,60 +30,18 @@
import javax.sql.rowset.serial.SerialClob;
import org.junit.Test;
-import org.mockito.Mockito;
-import org.teiid.core.TeiidComponentException;
+import org.teiid.common.buffer.BufferManager.TupleSourceType;
import org.teiid.core.types.ClobType;
import org.teiid.core.types.DataTypeManager;
import org.teiid.query.sql.symbol.ElementSymbol;
-
public class TestTupleBuffer {
- public static final class FakeBatchManager implements BatchManager {
- @Override
- public void remove() {
-
- }
-
- @Override
- public ManagedBatch createManagedBatch(final TupleBatch batch, boolean softCache)
- throws TeiidComponentException {
- return new ManagedBatch() {
-
- @Override
- public void remove() {
-
- }
-
- @Override
- public TupleBatch getBatch(boolean cache, String[] types)
- throws TeiidComponentException {
- return batch;
- }
-
- @Override
- public void setPrefersMemory(boolean prefers) {
-
- }
-
- @Override
- public CleanupHook getCleanupHook() {
- return null;
- }
- };
- }
-
- @Override
- public FileStore createStorage(String prefix) {
- return Mockito.mock(FileStore.class);
- }
- }
-
@Test public void testForwardOnly() throws Exception {
ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$
x.setType(DataTypeManager.DefaultDataClasses.INTEGER);
List<ElementSymbol> schema = Arrays.asList(x);
- TupleBuffer tb = new TupleBuffer(new FakeBatchManager(), "x", schema, null, 32); //$NON-NLS-1$
+ TupleBuffer tb = BufferManagerFactory.getStandaloneBufferManager().createTupleBuffer(schema, "x", TupleSourceType.PROCESSOR); //$NON-NLS-1$
tb.setForwardOnly(true);
tb.addTuple(Arrays.asList(1));
TupleBatch batch = tb.getBatch(1);
@@ -106,7 +64,7 @@
ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$
x.setType(DataTypeManager.DefaultDataClasses.CLOB);
List<ElementSymbol> schema = Arrays.asList(x);
- TupleBuffer tb = new TupleBuffer(new FakeBatchManager(), "x", schema, LobManager.getLobIndexes(schema), 32); //$NON-NLS-1$
+ TupleBuffer tb = BufferManagerFactory.getStandaloneBufferManager().createTupleBuffer(schema, "x", TupleSourceType.PROCESSOR); //$NON-NLS-1$
tb.setInlineLobs(false);
ClobType c = new ClobType(new SerialClob(new char[0]));
TupleBatch batch = new TupleBatch(1, new List[] {Arrays.asList(c)});
Added: trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBitSetTree.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBitSetTree.java (rev 0)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBitSetTree.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+ package org.teiid.common.buffer.impl;
+
+import static org.junit.Assert.*;
+
+import java.util.BitSet;
+import java.util.Random;
+
+import org.junit.Test;
+
+public class TestBitSetTree {
+
+ @Test public void testBitsSet() {
+ BitSetTree bst = new BitSetTree();
+ bst.set(1, true);
+ bst.set(100, true);
+ bst.set(10000, true);
+ bst.set(1000000, true);
+ assertEquals(4, bst.getBitsSet());
+ }
+
+ @Test public void testNextClearSet() {
+ BitSetTree bst = new BitSetTree();
+ BitSet bst1 = new BitSet();
+ Random r = new Random(1);
+ for (int i = 0; i < 1000; i++) {
+ int rand = r.nextInt() & BitSetTree.MAX_INDEX;
+ bst.set(rand, true);
+ bst1.set(rand, true);
+ }
+
+ for (int i = 0; i < 10000; i++) {
+ int rand = r.nextInt() & BitSetTree.MAX_INDEX;
+ assertEquals(bst1.nextClearBit(rand), bst.nextClearBit(rand));
+ assertEquals(bst1.nextSetBit(rand), bst.nextSetBit(rand));
+ }
+ }
+
+}
Property changes on: trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestBitSetTree.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStorageManager.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStorageManager.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStorageManager.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -25,6 +25,7 @@
import static org.junit.Assert.*;
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
@@ -59,7 +60,7 @@
assertEquals(0, sm.getUsedBufferSpace());
}
- @Test(expected=TeiidComponentException.class) public void testMaxSpace() throws Exception {
+ @Test(expected=IOException.class) public void testMaxSpace() throws Exception {
FileStorageManager sm = getStorageManager(null, null);
sm.setMaxBufferSpace(1);
String tsID = "0"; //$NON-NLS-1$
@@ -81,10 +82,11 @@
static Random r = new Random();
static void writeBytes(FileStore store)
- throws TeiidComponentException {
+ throws IOException {
byte[] bytes = new byte[2048];
r.nextBytes(bytes);
- long start = store.write(bytes, 0, bytes.length);
+ long start = store.getLength();
+ store.write(bytes, 0, bytes.length);
byte[] bytesRead = new byte[2048];
store.readFully(start, bytesRead, 0, bytesRead.length);
assertTrue(Arrays.equals(bytes, bytesRead));
Added: trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStoreCache.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStoreCache.java (rev 0)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStoreCache.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.common.buffer.impl;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.teiid.common.buffer.CacheEntry;
+import org.teiid.common.buffer.Serializer;
+
+public class TestFileStoreCache {
+
+ @Test public void testAddGetMultiBlock() throws Exception {
+ FileStoreCache fsc = new FileStoreCache();
+ fsc.setStorageManager(new MemoryStorageManager());
+ fsc.initialize();
+
+ CacheEntry ce = new CacheEntry(2l);
+ Serializer<Object> s = new Serializer<Object>() {
+ @Override
+ public Object deserialize(ObjectInputStream ois)
+ throws IOException, ClassNotFoundException {
+ return ois.readObject();
+ }
+
+ @Override
+ public Long getId() {
+ return 1l;
+ }
+
+ @Override
+ public void serialize(Object obj, ObjectOutputStream oos)
+ throws IOException {
+ oos.writeObject(obj);
+ }
+
+ @Override
+ public boolean useSoftCache() {
+ return false;
+ }
+ };
+ fsc.createCacheGroup(s.getId());
+ List<Object> cacheObject = Arrays.asList(new Object[10000]);
+ ce.setObject(cacheObject);
+ fsc.add(ce, s);
+
+ ce = fsc.get(2l, s);
+ assertEquals(cacheObject, ce.getObject());
+ }
+
+}
Property changes on: trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStoreCache.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestSizeUtility.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestSizeUtility.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestSizeUtility.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -34,7 +34,6 @@
import java.util.List;
import org.junit.Test;
-import org.teiid.common.buffer.TupleBatch;
public class TestSizeUtility {
@@ -43,7 +42,7 @@
}
public void helpTestGetSize(Object obj, long expectedSize) {
- long actualSize = new SizeUtility().getSize(obj, true, false);
+ long actualSize = new SizeUtility(null).getSize(obj, true, false);
assertEquals("Got unexpected size: ", expectedSize, actualSize); //$NON-NLS-1$
}
@@ -176,9 +175,7 @@
String[] types = {"string", "integer", "boolean", "double", "string", "integer"}; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ //$NON-NLS-5$//$NON-NLS-6$
- TupleBatch tb = new TupleBatch(1, expected);
- tb.setDataTypes(types);
- long actualSize = new SizeUtility().getBatchSize(tb);
+ long actualSize = new SizeUtility(types).getBatchSize(Arrays.asList(expected));
assertEquals("Got unexpected size: ", 2667, actualSize); //$NON-NLS-1$
}
Modified: trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestSplittableStorageManager.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestSplittableStorageManager.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestSplittableStorageManager.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -43,10 +43,18 @@
TestFileStorageManager.writeBytes(store);
assertEquals(2, msm.getCreated());
+
+ store.setLength(10000);
+ assertEquals(5, msm.getCreated());
+
+ store.setLength(100);
+
+ assertEquals(4, msm.getRemoved());
+
store.remove();
- assertEquals(2, msm.getRemoved());
+ assertEquals(5, msm.getRemoved());
}
@Test public void testTruncate() throws Exception {
@@ -64,7 +72,7 @@
assertEquals(2, msm.getCreated());
- store.truncate(100);
+ store.setLength(100);
assertEquals(1, msm.getRemoved());
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestCachedResults.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestCachedResults.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestCachedResults.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -30,8 +30,9 @@
import org.teiid.cache.Cache;
import org.teiid.cache.DefaultCache;
import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.BufferManagerFactory;
import org.teiid.common.buffer.TupleBuffer;
-import org.teiid.common.buffer.TestTupleBuffer.FakeBatchManager;
+import org.teiid.common.buffer.BufferManager.TupleSourceType;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.UnitTestUtil;
import org.teiid.dqp.service.FakeBufferService;
@@ -53,7 +54,7 @@
ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$
x.setType(DataTypeManager.DefaultDataClasses.INTEGER);
List<ElementSymbol> schema = Arrays.asList(x);
- TupleBuffer tb = new TupleBuffer(new FakeBatchManager(), "x", schema, null, 4); //$NON-NLS-1$
+ TupleBuffer tb = BufferManagerFactory.getStandaloneBufferManager().createTupleBuffer(schema, "x", TupleSourceType.PROCESSOR); //$NON-NLS-1$
tb.setForwardOnly(false);
tb.addTuple(Arrays.asList(1));
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -311,7 +311,7 @@
reqMsg.setCursorType(ResultSet.TYPE_FORWARD_ONLY);
DQPWorkContext.getWorkContext().getSession().setSessionId(sessionid);
DQPWorkContext.getWorkContext().getSession().setUserName(userName);
- ((BufferManagerImpl)core.getBufferManager()).setProcessorBatchSize(2);
+ ((BufferManagerImpl)core.getBufferManager()).setProcessorBatchSize(1);
Future<ResultsMessage> message = core.executeRequest(reqMsg.getExecutionId(), reqMsg);
ResultsMessage rm = message.get(500000, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
@@ -337,7 +337,7 @@
message = core.processCursorRequest(reqMsg.getExecutionId(), (j + 2) * rowsPerBatch + 1, rowsPerBatch);
rm = message.get(5000, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
- assertEquals(rowsPerBatch, rm.getResults().length);
+ assertEquals(rowsPerBatch, rm.getResultsList().size());
}
}
@@ -351,11 +351,11 @@
reqMsg.setCursorType(ResultSet.TYPE_FORWARD_ONLY);
DQPWorkContext.getWorkContext().getSession().setSessionId(sessionid);
DQPWorkContext.getWorkContext().getSession().setUserName(userName);
- ((BufferManagerImpl)core.getBufferManager()).setProcessorBatchSize(2);
+ ((BufferManagerImpl)core.getBufferManager()).setProcessorBatchSize(1);
Future<ResultsMessage> message = core.executeRequest(reqMsg.getExecutionId(), reqMsg);
ResultsMessage rm = message.get(500000, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
- assertEquals(8, rm.getResults().length);
+ assertEquals(8, rm.getResultsList().size());
RequestWorkItem item = core.getRequestWorkItem(DQPWorkContext.getWorkContext().getRequestID(reqMsg.getExecutionId()));
assertEquals(100, item.resultsBuffer.getRowCount());
}
Modified: trunk/engine/src/test/java/org/teiid/dqp/service/AutoGenDataService.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/service/AutoGenDataService.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/test/java/org/teiid/dqp/service/AutoGenDataService.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -95,7 +95,7 @@
results = new List[] {Arrays.asList(1)};
}
- final AtomicResultsMessage msg = ConnectorWorkItem.createResultsMessage(results, projectedSymbols);
+ final AtomicResultsMessage msg = ConnectorWorkItem.createResultsMessage(results);
msg.setFinalRow(rows);
return new ConnectorWork() {
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -188,19 +188,19 @@
tempStore = gtsi.getTempTableStore();
metadata = new TempMetadataAdapter(RealMetadataFactory.example1Cached(), tempStore.getMetadataStore());
execute("create local temporary table x (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
- for (int i = 0; i < 86; i++) {
+ for (int i = 0; i < 300; i++) {
execute("insert into x (e2, e1) select e2, e1 from pm1.g1", new List[] {Arrays.asList(6)}); //$NON-NLS-1$
}
setupTransaction(Connection.TRANSACTION_SERIALIZABLE);
- execute("select count(*) from x", new List[] {Arrays.asList(516)});
- gtsi.updateMatViewRow("X", Arrays.asList(1), true);
+ execute("select count(e1) from x", new List[] {Arrays.asList(1500)});
+ gtsi.updateMatViewRow("X", Arrays.asList(2), true);
tc=null;
//outside of the transaction we can see the row removed
- execute("select count(*) from x", new List[] {Arrays.asList(515)});
+ execute("select count(e1) from x", new List[] {Arrays.asList(1499)});
//back in the transaction we see the original state
setupTransaction(Connection.TRANSACTION_SERIALIZABLE);
- execute("select count(*) from x", new List[] {Arrays.asList(516)});
+ execute("select count(e1) from x", new List[] {Arrays.asList(1500)});
synch.afterCompletion(Status.STATUS_COMMITTED);
}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -33,9 +33,8 @@
import org.junit.Test;
import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.BufferManagerFactory;
import org.teiid.common.buffer.TupleBuffer;
-import org.teiid.common.buffer.impl.BufferManagerImpl;
-import org.teiid.common.buffer.impl.MemoryStorageManager;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidException;
import org.teiid.core.types.DataTypeManager;
@@ -461,16 +460,8 @@
TestProcessor.examineResults((List[])expected.toArray(new List[expected.size()]), bufferMgr, id);
}
- private BufferManager createCustomBufferMgr(int batchSize) throws TeiidComponentException {
- BufferManagerImpl bufferMgr = new BufferManagerImpl();
- bufferMgr.setConnectorBatchSize(batchSize);
- bufferMgr.setProcessorBatchSize(batchSize);
- bufferMgr.initialize();
-
- // Add unmanaged memory storage manager
- bufferMgr.setStorageManager(new MemoryStorageManager());
-
- return bufferMgr;
+ private BufferManager createCustomBufferMgr(int batchSize) {
+ return BufferManagerFactory.getTestBufferManager(200000, batchSize);
}
public void helpTestVirtualDepJoin(boolean pushCriteria) throws Exception {
Modified: trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestElementSymbol.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestElementSymbol.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestElementSymbol.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -127,22 +127,22 @@
@Test public void testEquals5() {
ElementSymbol es = sampleElement1();
- helpEquals(es, (ElementSymbol)es.clone(), true);
+ helpEquals(es, es.clone(), true);
}
@Test public void testEquals6() {
ElementSymbol es = sampleElement2();
- helpEquals(es, (ElementSymbol)es.clone(), true);
+ helpEquals(es, es.clone(), true);
}
@Test public void testEquals7() {
ElementSymbol es = sampleElement3();
- helpEquals(es, (ElementSymbol)es.clone(), true);
+ helpEquals(es, es.clone(), true);
}
@Test public void testEquals8() {
ElementSymbol es = sampleElement4();
- helpEquals(es, (ElementSymbol)es.clone(), true);
+ helpEquals(es, es.clone(), true);
}
// Compare fully-qualified to short versions
@@ -190,7 +190,7 @@
@Test public void testCloneEquivalence(){
ElementSymbol s1 = sampleElement1();
- ElementSymbol s2 = (ElementSymbol)s1.clone();
+ ElementSymbol s2 = s1.clone();
int equals = 0;
UnitTestUtil.helpTestEquivalence(equals, s1, s2);
}
@@ -225,31 +225,31 @@
@Test public void testClone1() {
ElementSymbol e1 = sampleElement1();
- ElementSymbol copy = (ElementSymbol) e1.clone();
+ ElementSymbol copy = e1.clone();
helpEquals(e1, copy, true);
}
@Test public void testClone2() {
ElementSymbol e1 = sampleElement2();
- ElementSymbol copy = (ElementSymbol) e1.clone();
+ ElementSymbol copy = e1.clone();
helpEquals(e1, copy, true);
}
@Test public void testClone3() {
ElementSymbol e1 = sampleElement3();
- ElementSymbol copy = (ElementSymbol) e1.clone();
+ ElementSymbol copy = e1.clone();
helpEquals(e1, copy, true);
}
@Test public void testClone4() {
ElementSymbol e1 = sampleElement4();
- ElementSymbol copy = (ElementSymbol) e1.clone();
+ ElementSymbol copy = e1.clone();
helpEquals(e1, copy, true);
}
@Test public void testClone5() {
ElementSymbol e1 = sampleElement1();
- ElementSymbol copy = (ElementSymbol) e1.clone();
+ ElementSymbol copy = e1.clone();
helpEquals(e1, copy, true);
// Change original, clone shouldn't change
Modified: trunk/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -33,6 +33,7 @@
import org.teiid.common.buffer.BufferManager;
import org.teiid.common.buffer.impl.BufferManagerImpl;
import org.teiid.common.buffer.impl.FileStorageManager;
+import org.teiid.common.buffer.impl.FileStoreCache;
import org.teiid.common.buffer.impl.MemoryStorageManager;
import org.teiid.common.buffer.impl.SplittableStorageManager;
import org.teiid.core.TeiidComponentException;
@@ -105,10 +106,11 @@
fsm.setMaxBufferSpace(maxBufferSpace*MB);
SplittableStorageManager ssm = new SplittableStorageManager(fsm);
ssm.setMaxFileSize(maxFileSize);
- ssm.initialize();
- this.bufferMgr.setStorageManager(ssm);
+ FileStoreCache fsc = new FileStoreCache();
+ fsc.setStorageManager(ssm);
+ this.bufferMgr.setCache(fsc);
} else {
- this.bufferMgr.setStorageManager(new MemoryStorageManager());
+ this.bufferMgr.setCache(new MemoryStorageManager());
}
} catch(TeiidComponentException e) {
@@ -129,7 +131,7 @@
}
}
- public BufferManager getBufferManager() {
+ public BufferManagerImpl getBufferManager() {
return this.bufferMgr;
}
Modified: trunk/runtime/src/test/java/org/teiid/dqp/service/buffer/TestLocalBufferService.java
===================================================================
--- trunk/runtime/src/test/java/org/teiid/dqp/service/buffer/TestLocalBufferService.java 2011-09-20 00:16:04 UTC (rev 3501)
+++ trunk/runtime/src/test/java/org/teiid/dqp/service/buffer/TestLocalBufferService.java 2011-09-21 04:13:59 UTC (rev 3502)
@@ -31,6 +31,7 @@
import org.teiid.common.buffer.BufferManager;
import org.teiid.common.buffer.impl.BufferManagerImpl;
import org.teiid.common.buffer.impl.FileStorageManager;
+import org.teiid.common.buffer.impl.FileStoreCache;
import org.teiid.common.buffer.impl.SplittableStorageManager;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.UnitTestUtil;
@@ -53,8 +54,8 @@
assertTrue("does not end with one", svc.getBufferDirectory().getParent().endsWith("1")); //$NON-NLS-1$ //$NON-NLS-2$
assertTrue(svc.isUseDisk());
- BufferManagerImpl mgr = (BufferManagerImpl) svc.getBufferManager();
- SplittableStorageManager ssm = (SplittableStorageManager)mgr.getStorageManager();
+ BufferManagerImpl mgr = svc.getBufferManager();
+ SplittableStorageManager ssm = (SplittableStorageManager)((FileStoreCache)mgr.getCache()).getStorageManager();
assertTrue(((FileStorageManager)ssm.getStorageManager()).getDirectory().endsWith(svc.getBufferDirectory().getName()));
}
[View Less]
13 years, 6 months
teiid SVN: r3501 - in branches/7.1.1.CP3_SOA-3362: adminshell and 37 other directories.
by teiid-commits@lists.jboss.org
Author: loleary
Date: 2011-09-19 20:16:04 -0400 (Mon, 19 Sep 2011)
New Revision: 3501
Modified:
branches/7.1.1.CP3_SOA-3362/adminshell/pom.xml
branches/7.1.1.CP3_SOA-3362/api/pom.xml
branches/7.1.1.CP3_SOA-3362/build/kits/jboss-container/teiid-releasenotes.html
branches/7.1.1.CP3_SOA-3362/build/pom.xml
branches/7.1.1.CP3_SOA-3362/cache-jbosscache/pom.xml
branches/7.1.1.CP3_SOA-3362/client-jdk15/pom.xml
branches/7.1.1.CP3_SOA-3362/client/pom.xml
branches/7.1.1.CP3_SOA-…
[View More]3362/common-core/pom.xml
branches/7.1.1.CP3_SOA-3362/connectors/connector-file/pom.xml
branches/7.1.1.CP3_SOA-3362/connectors/connector-ldap/pom.xml
branches/7.1.1.CP3_SOA-3362/connectors/connector-salesforce/pom.xml
branches/7.1.1.CP3_SOA-3362/connectors/connector-ws/pom.xml
branches/7.1.1.CP3_SOA-3362/connectors/pom.xml
branches/7.1.1.CP3_SOA-3362/connectors/salesforce-api/pom.xml
branches/7.1.1.CP3_SOA-3362/connectors/sandbox/pom.xml
branches/7.1.1.CP3_SOA-3362/connectors/sandbox/translator-yahoo/pom.xml
branches/7.1.1.CP3_SOA-3362/connectors/translator-file/pom.xml
branches/7.1.1.CP3_SOA-3362/connectors/translator-jdbc/pom.xml
branches/7.1.1.CP3_SOA-3362/connectors/translator-ldap/pom.xml
branches/7.1.1.CP3_SOA-3362/connectors/translator-loopback/pom.xml
branches/7.1.1.CP3_SOA-3362/connectors/translator-salesforce/pom.xml
branches/7.1.1.CP3_SOA-3362/connectors/translator-ws/pom.xml
branches/7.1.1.CP3_SOA-3362/console/pom.xml
branches/7.1.1.CP3_SOA-3362/documentation/admin-guide/pom.xml
branches/7.1.1.CP3_SOA-3362/documentation/caching-guide/pom.xml
branches/7.1.1.CP3_SOA-3362/documentation/client-developers-guide/pom.xml
branches/7.1.1.CP3_SOA-3362/documentation/developer-guide/pom.xml
branches/7.1.1.CP3_SOA-3362/documentation/pom.xml
branches/7.1.1.CP3_SOA-3362/documentation/quick-start-example/pom.xml
branches/7.1.1.CP3_SOA-3362/documentation/reference/pom.xml
branches/7.1.1.CP3_SOA-3362/engine/pom.xml
branches/7.1.1.CP3_SOA-3362/hibernate-dialect/pom.xml
branches/7.1.1.CP3_SOA-3362/jboss-integration/pom.xml
branches/7.1.1.CP3_SOA-3362/metadata/pom.xml
branches/7.1.1.CP3_SOA-3362/pom.xml
branches/7.1.1.CP3_SOA-3362/runtime/pom.xml
branches/7.1.1.CP3_SOA-3362/test-integration/common/pom.xml
branches/7.1.1.CP3_SOA-3362/test-integration/db/pom.xml
branches/7.1.1.CP3_SOA-3362/test-integration/pom.xml
Log:
Updated pom.xml to reflect release version 7.1.1.CP3-r3467
Modified: branches/7.1.1.CP3_SOA-3362/adminshell/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/adminshell/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/adminshell/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>teiid-parent</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>teiid-adminshell</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/api/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/api/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/api/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>teiid-parent</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>teiid-api</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/build/kits/jboss-container/teiid-releasenotes.html
===================================================================
--- branches/7.1.1.CP3_SOA-3362/build/kits/jboss-container/teiid-releasenotes.html 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/build/kits/jboss-container/teiid-releasenotes.html 2011-09-20 00:16:04 UTC (rev 3501)
@@ -157,6 +157,45 @@
<h2><a name="Details">Detailed Release Notes</a></h2>
Detailed Release Notes - Teiid - Version ${project.version}
+
+<h3> Bug
+</h3>
+<h4>From ${project.version}</h4>
+<ul>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1706'>TEIID-1706</a>] - JOIN between two text file data sources extremely slow</li>
+</ul>
+<h4>From 7.1.1.CP3</h4>
+<ul>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1495'>TEIID-1495</a>] - Validate the TeraData Translator</li>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1654'>TEIID-1654</a>] - Node returns 0 rows for cached view when other node had it loaded and leaves cluster</li>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1656'>TEIID-1656</a>] - Add pushdown support for grouping expression over a UNION</li>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1652'>TEIID-1652</a>] - ODBC Data Row results should be batched</li>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1653'>TEIID-1653</a>] - Support Cursoring over ODBC protocol ( support UseDeclareFetch = 1)</li>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1493'>TEIID-1493</a>] - In a cluster the distributed cache is cleared by a node rejoining</li>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1657'>TEIID-1657</a>] - refreshMatView does not work correctly for an internal materialized view when clustering is enabled</li>
+</ul>
+<h4>From 7.1.1.CP2</h4>
+<ul>
+<li>[<a href='https://issues.jboss.org/browse/SOA-3103'>SOA-3103</a>] - TeraData Translator for EDS</li>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1631'>TEIID-1631</a>] - ODBC SQLDescribeCol does not work, When used with the Prepare Statement</li>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1623'>TEIID-1623</a>] - ODBC numeric and string precision issues</li>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1622'>TEIID-1622</a>] - Optional JOIN hints don't get optimized out for UNION ALL view</li>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1571'>TEIID-1571</a>] - Error due to merge virtual with join and group by</li>
+</ul>
+<h4>From 7.1.1.CP1</h4>
+<ul>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1564'>TEIID-1564</a>] - Clustered Caching Not Working</li>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1515'>TEIID-1515</a>] - ODBC does not report primarykeys on the tables</li>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1467'>TEIID-1467</a>] - Procedures in Teiid are not Resolvable if Their Models are Marked as Not Visible</li>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1489'>TEIID-1489</a>] - Teiid assumes fqns in transformations, but they are no longer required to be there</li>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1498'>TEIID-1498</a>] - Incorrect rewrite of not disjunctive criteria</li>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1506'>TEIID-1506</a>] - ODBC Driver reporting BigInteger, BigDecimal columns as Strings</li>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1492'>TEIID-1492</a>] - StackOverflowError in DefaultCache</li>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1505'>TEIID-1505</a>] - MaxActivePlans is not being read from the configuration</li>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1477'>TEIID-1477</a>] - Teiid ODBC has an issue supporting the postgres 8.01 client</li>
+<li>[<a href='https://issues.jboss.org/browse/TEIID-1469'>TEIID-1469</a>] - Teiid Plugin uses Invalid Datatype Mask for SessionID Parameter to Terminate Session Operation</li>
+</ul>
+
<h2><a name="Documentation">Documentation and Help</a></h2>
@@ -199,4 +238,4 @@
information.</p>
</BODY>
-</HTML>
\ No newline at end of file
+</HTML>
Modified: branches/7.1.1.CP3_SOA-3362/build/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/build/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/build/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -2,7 +2,7 @@
<parent>
<artifactId>teiid-parent</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>teiid</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/cache-jbosscache/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/cache-jbosscache/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/cache-jbosscache/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>teiid-parent</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>teiid-cache-jbosscache</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/client/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/client/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/client/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>teiid-parent</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>teiid-client</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/client-jdk15/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/client-jdk15/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/client-jdk15/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>teiid-parent</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>teiid-client-jdk15</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/common-core/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/common-core/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/common-core/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>teiid-parent</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>teiid-common-core</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/connectors/connector-file/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/connectors/connector-file/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/connectors/connector-file/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>connectors</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>connector-file</artifactId>
@@ -55,4 +55,4 @@
</plugin>
</plugins>
</build>
-</project>
\ No newline at end of file
+</project>
Modified: branches/7.1.1.CP3_SOA-3362/connectors/connector-ldap/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/connectors/connector-ldap/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/connectors/connector-ldap/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -2,7 +2,7 @@
<parent>
<artifactId>connectors</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>connector-ldap</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/connectors/connector-salesforce/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/connectors/connector-salesforce/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/connectors/connector-salesforce/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>connectors</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>connector-salesforce</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/connectors/connector-ws/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/connectors/connector-ws/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/connectors/connector-ws/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>connectors</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>connector-ws</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/connectors/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/connectors/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/connectors/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>teiid-parent</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.teiid</groupId>
Modified: branches/7.1.1.CP3_SOA-3362/connectors/salesforce-api/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/connectors/salesforce-api/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/connectors/salesforce-api/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -2,7 +2,7 @@
<parent>
<artifactId>connectors</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>salesforce-api</artifactId>
@@ -11,4 +11,4 @@
<description>The java API for the Salesforce.com partner web service API</description>
<dependencies>
</dependencies>
-</project>
\ No newline at end of file
+</project>
Modified: branches/7.1.1.CP3_SOA-3362/connectors/sandbox/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/connectors/sandbox/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/connectors/sandbox/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>connectors</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.teiid.connectors</groupId>
Modified: branches/7.1.1.CP3_SOA-3362/connectors/sandbox/translator-yahoo/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/connectors/sandbox/translator-yahoo/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/connectors/sandbox/translator-yahoo/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>sandbox</artifactId>
<groupId>org.jboss.teiid.connectors</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>translator-yahoo</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/connectors/translator-file/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/connectors/translator-file/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/connectors/translator-file/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>connectors</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>translator-file</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/connectors/translator-jdbc/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/connectors/translator-jdbc/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/connectors/translator-jdbc/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>connectors</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>translator-jdbc</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/connectors/translator-ldap/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/connectors/translator-ldap/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/connectors/translator-ldap/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -2,7 +2,7 @@
<parent>
<artifactId>connectors</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>translator-ldap</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/connectors/translator-loopback/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/connectors/translator-loopback/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/connectors/translator-loopback/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>connectors</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>translator-loopback</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/connectors/translator-salesforce/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/connectors/translator-salesforce/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/connectors/translator-salesforce/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>connectors</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>translator-salesforce</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/connectors/translator-ws/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/connectors/translator-ws/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/connectors/translator-ws/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>connectors</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>translator-ws</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/console/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/console/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/console/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -4,7 +4,7 @@
<parent>
<artifactId>teiid-parent</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -173,4 +173,4 @@
</build>
-</project>
\ No newline at end of file
+</project>
Modified: branches/7.1.1.CP3_SOA-3362/documentation/admin-guide/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/documentation/admin-guide/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/documentation/admin-guide/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -2,7 +2,7 @@
<parent>
<groupId>org.jboss.teiid</groupId>
<artifactId>documentation</artifactId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>admin-guide</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/documentation/caching-guide/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/documentation/caching-guide/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/documentation/caching-guide/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -2,7 +2,7 @@
<parent>
<groupId>org.jboss.teiid</groupId>
<artifactId>documentation</artifactId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>caching-guide</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/documentation/client-developers-guide/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/documentation/client-developers-guide/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/documentation/client-developers-guide/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -2,7 +2,7 @@
<parent>
<groupId>org.jboss.teiid</groupId>
<artifactId>documentation</artifactId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>client-developers-guide</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/documentation/developer-guide/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/documentation/developer-guide/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/documentation/developer-guide/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -2,7 +2,7 @@
<parent>
<groupId>org.jboss.teiid</groupId>
<artifactId>documentation</artifactId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>developer-guide</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/documentation/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/documentation/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/documentation/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -2,7 +2,7 @@
<parent>
<artifactId>teiid-parent</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version> </parent>
+ <version>7.1.1.CP3-r3467</version> </parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.teiid</groupId>
<artifactId>documentation</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/documentation/quick-start-example/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/documentation/quick-start-example/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/documentation/quick-start-example/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -2,7 +2,7 @@
<parent>
<groupId>org.jboss.teiid</groupId>
<artifactId>documentation</artifactId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>quick-start-example</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/documentation/reference/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/documentation/reference/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/documentation/reference/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -2,7 +2,7 @@
<parent>
<groupId>org.jboss.teiid</groupId>
<artifactId>documentation</artifactId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>reference</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/engine/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/engine/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/engine/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>teiid-parent</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>teiid-engine</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/hibernate-dialect/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/hibernate-dialect/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/hibernate-dialect/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -2,7 +2,7 @@
<parent>
<artifactId>teiid-parent</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>teiid-hibernate-dialect</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/jboss-integration/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/jboss-integration/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/jboss-integration/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -2,7 +2,7 @@
<parent>
<artifactId>teiid-parent</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.teiid</groupId>
Modified: branches/7.1.1.CP3_SOA-3362/metadata/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/metadata/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/metadata/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>teiid-parent</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>teiid-metadata</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -5,15 +5,15 @@
<artifactId>teiid-parent</artifactId>
<packaging>pom</packaging>
<name>Teiid</name>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
<description>Federated SQL and XML query engine.</description>
<properties>
<ant.version>1.7.0</ant.version>
<site.url>http://www.jboss.org/teiid</site.url>
</properties>
<scm>
- <connection>scm:svn:https://anonsvn.jboss.org/repos/teiid/tags/teiid-7.1.x</connection>
- <developerConnection>scm:svn:https://svn.jboss.org/repos/teiid/tags/teiid-7.1.x</developerConnection>
+ <connection>scm:svn:https://anonsvn.jboss.org/repos/teiid/branches/7.1.1.CP3_SOA-3362</connection>
+ <developerConnection>scm:svn:https://svn.jboss.org/repos/teiid/branches/7.1.1.CP3_SOA-3362</developerConnection>
</scm>
<licenses>
<license>
Modified: branches/7.1.1.CP3_SOA-3362/runtime/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/runtime/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/runtime/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>teiid-parent</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.teiid</groupId>
@@ -91,4 +91,4 @@
<scope>provided</scope>
</dependency>
</dependencies>
-</project>
\ No newline at end of file
+</project>
Modified: branches/7.1.1.CP3_SOA-3362/test-integration/common/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/test-integration/common/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/test-integration/common/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>teiid-test-integration</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>test-integration-common</artifactId>
Modified: branches/7.1.1.CP3_SOA-3362/test-integration/db/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/test-integration/db/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/test-integration/db/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -9,7 +9,7 @@
<parent>
<artifactId>teiid-test-integration</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
Modified: branches/7.1.1.CP3_SOA-3362/test-integration/pom.xml
===================================================================
--- branches/7.1.1.CP3_SOA-3362/test-integration/pom.xml 2011-09-20 00:14:47 UTC (rev 3500)
+++ branches/7.1.1.CP3_SOA-3362/test-integration/pom.xml 2011-09-20 00:16:04 UTC (rev 3501)
@@ -3,7 +3,7 @@
<parent>
<artifactId>teiid-parent</artifactId>
<groupId>org.jboss.teiid</groupId>
- <version>7.1.1.CP3</version>
+ <version>7.1.1.CP3-r3467</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>teiid-test-integration</artifactId>
[View Less]
13 years, 6 months
teiid SVN: r3500 - in branches/7.1.1.CP3_SOA-3362/engine/src: test/java/org/teiid/query/processor and 1 other directory.
by teiid-commits@lists.jboss.org
Author: loleary
Date: 2011-09-19 20:14:47 -0400 (Mon, 19 Sep 2011)
New Revision: 3500
Modified:
branches/7.1.1.CP3_SOA-3362/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePlanJoins.java
branches/7.1.1.CP3_SOA-3362/engine/src/test/java/org/teiid/query/processor/TestTextTable.java
Log:
TEIID-1706 fix to join planning with nested tables
Modified: branches/7.1.1.CP3_SOA-3362/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePlanJoins.java
==============…
[View More]=====================================================
--- branches/7.1.1.CP3_SOA-3362/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePlanJoins.java 2011-09-19 23:45:18 UTC (rev 3499)
+++ branches/7.1.1.CP3_SOA-3362/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePlanJoins.java 2011-09-20 00:14:47 UTC (rev 3500)
@@ -470,7 +470,8 @@
}
JoinType jt = (JoinType)root.getProperty(NodeConstants.Info.JOIN_TYPE);
- boolean treatJoinAsSource = jt.isOuter() || root.getProperty(NodeConstants.Info.ACCESS_PATTERNS) != null || root.hasProperty(NodeConstants.Info.MAKE_DEP);
+ boolean treatJoinAsSource = jt.isOuter() || root.getProperty(NodeConstants.Info.ACCESS_PATTERNS) != null
+ || root.hasProperty(NodeConstants.Info.MAKE_DEP) || !root.getExportedCorrelatedReferences().isEmpty();
if (treatJoinAsSource) {
currentRegion.addJoinSourceNode(root);
Modified: branches/7.1.1.CP3_SOA-3362/engine/src/test/java/org/teiid/query/processor/TestTextTable.java
===================================================================
--- branches/7.1.1.CP3_SOA-3362/engine/src/test/java/org/teiid/query/processor/TestTextTable.java 2011-09-19 23:45:18 UTC (rev 3499)
+++ branches/7.1.1.CP3_SOA-3362/engine/src/test/java/org/teiid/query/processor/TestTextTable.java 2011-09-20 00:14:47 UTC (rev 3500)
@@ -22,6 +22,8 @@
package org.teiid.query.processor;
+import static org.junit.Assert.*;
+import static org.teiid.query.optimizer.TestOptimizer.*;
import static org.teiid.query.processor.TestProcessor.*;
import java.util.Arrays;
@@ -34,7 +36,13 @@
import org.teiid.core.types.InputStreamFactory;
import org.teiid.core.util.UnitTestUtil;
import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.processor.relational.JoinNode;
+import org.teiid.query.processor.relational.NestedTableJoinStrategy;
+import org.teiid.query.processor.relational.RelationalPlan;
import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.RealMetadataFactory;
@SuppressWarnings({"unchecked", "nls"})
public class TestTextTable {
@@ -208,8 +216,27 @@
};
process(sql, expected);
- }
+ }
+ @Test public void testTextTableJoin() throws Exception {
+ String sql = "select z.* from (select x.* from (select * from pm1.g1 where e1 = 'c') y, texttable(e1 || '\n' || e2 || '\n' || e3 COLUMNS x string) x) as z, " +
+ "(select x.* from (select * from pm1.g1 where e1 = 'c') y, texttable(e1 || '\n' || e2 || '\n' || e3 COLUMNS x string) x) as z1 where z.x = z1.x order by z.x";
+
+ List[] expected = new List[] {
+ Arrays.asList("1"),
+ Arrays.asList("c"),
+ Arrays.asList("true"),
+ };
+
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+ RelationalPlan plan = (RelationalPlan)helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+ // The root node's child is a sortNode so we want the sortNode's first child
+ JoinNode join = (JoinNode) plan.getRootNode().getChildren()[0].getChildren()[0];
+ assertTrue(!(join.getJoinStrategy() instanceof NestedTableJoinStrategy));
+ helpProcess(plan, createCommandContext(), dataManager, expected);
+ }
+
public static void process(String sql, List[] expectedResults) throws Exception {
FakeDataManager dataManager = new FakeDataManager();
sampleData1(dataManager);
[View Less]
13 years, 6 months