com.bigdata.relation
Class AbstractResource<E>

java.lang.Object
  extended by com.bigdata.relation.AbstractResource<E>
Type Parameters:
E -
All Implemented Interfaces:
IMutableResource<E>, ILocatableResource<E>
Direct Known Subclasses:
AbstractRelation, AbstractTripleStore, BigdataFileSystem

public abstract class AbstractResource<E>
extends Object
implements IMutableResource<E>

Base class for locatable resources.

Version:
$Id: AbstractResource.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson

Nested Class Summary
static interface AbstractResource.Options
          Options for locatable resources.
 
Field Summary
protected static org.apache.log4j.Logger log
           
 
Constructor Summary
protected AbstractResource(IIndexManager indexManager, String namespace, Long timestamp, Properties properties)
           
 
Method Summary
protected  IResourceLock acquireExclusiveLock()
          Acquires an exclusive lock for the getNamespace().
 void create()
          Create any logically contained resources (relations, indices).
 void destroy()
          Destroy any logically contained resources (relations, indices).
 int getChunkCapacity()
          The target chunk size.
 int getChunkOfChunksCapacity()
          The capacity of the buffers accumulating chunks from concurrent producers.
 long getChunkTimeout()
          The timeout in milliseconds that the BlockingBuffer will wait for another chunk to combine with the current chunk before returning the current chunk.
 ILocatableResource getContainer()
          Return the container.
 String getContainerNamespace()
          The identifier for the containing resource.
 ExecutorService getExecutorService()
           
 int getFullyBufferedReadThreshold()
          If the estimated range count for an IAccessPath.iterator(int, int) is LTE this threshold then do a fully buffered (synchronous) read.
 IIndexManager getIndexManager()
          Return the object used to locate indices, relations, and relation containers and to execute operations on those resources.
 int getMaxParallelSubqueries()
          The maximum #of subqueries for the first join dimension that will be issued in parallel.
 String getNamespace()
          The identifying namespace.
 Properties getProperties()
          Return an object wrapping the properties specified to the ctor.
protected  String getProperty(String localName, String defaultValue)
          Resolve the property value using the IIndexManager, the namespace of the resource, and the Properties instance to be tested as hidden parameters.
protected
<T> T
getProperty(String name, String defaultValue, IValidator<T> validator)
          Resolves, parses, and validates the property value.
 long getTimestamp()
          The timestamp associated with the view of the resource.
 boolean isForceSerialExecution()
          When true, rule sets will be forced to execute sequentially even when they are not flagged as a sequential program.
 boolean isNestedSubquery()
          When true the NestedSubqueryWithJoinThreadsTask is applied.
 String toString()
          The class name, timestamp and namespace for the relation view.
protected  void unlock(IResourceLock resourceLock)
          Release the lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected static final transient org.apache.log4j.Logger log
Constructor Detail

AbstractResource

protected AbstractResource(IIndexManager indexManager,
                           String namespace,
                           Long timestamp,
                           Properties properties)
Method Detail

getChunkOfChunksCapacity

public final int getChunkOfChunksCapacity()
The capacity of the buffers accumulating chunks from concurrent producers.

See Also:
AbstractResource.Options.CHUNK_OF_CHUNKS_CAPACITY

getChunkCapacity

public final int getChunkCapacity()
The target chunk size.

See Also:
AbstractResource.Options.CHUNK_CAPACITY

getChunkTimeout

public final long getChunkTimeout()
The timeout in milliseconds that the BlockingBuffer will wait for another chunk to combine with the current chunk before returning the current chunk. This may be ZERO (0) to disable the chunk combiner.

See Also:
AbstractResource.Options.CHUNK_TIMEOUT

getFullyBufferedReadThreshold

public int getFullyBufferedReadThreshold()
If the estimated range count for an IAccessPath.iterator(int, int) is LTE this threshold then do a fully buffered (synchronous) read. Otherwise we will do an asynchronous read.

See Also:
AbstractResource.Options.FULLY_BUFFERED_READ_THRESHOLD

isForceSerialExecution

public boolean isForceSerialExecution()
When true, rule sets will be forced to execute sequentially even when they are not flagged as a sequential program.

See Also:
AbstractResource.Options.FORCE_SERIAL_EXECUTION

getMaxParallelSubqueries

public int getMaxParallelSubqueries()
The maximum #of subqueries for the first join dimension that will be issued in parallel. Use ZERO(0) to avoid submitting tasks to the ExecutorService entirely and ONE (1) to submit a single task at a time to the ExecutorService.

See Also:
AbstractResource.Options.MAX_PARALLEL_SUBQUERIES

isNestedSubquery

public boolean isNestedSubquery()
When true the NestedSubqueryWithJoinThreadsTask is applied. Otherwise the JoinMasterTask is applied.

See Also:
AbstractResource.Options.NESTED_SUBQUERY

getNamespace

public final String getNamespace()
Description copied from interface: ILocatableResource
The identifying namespace.

Specified by:
getNamespace in interface ILocatableResource<E>

getContainerNamespace

public final String getContainerNamespace()
Description copied from interface: ILocatableResource
The identifier for the containing resource.

Specified by:
getContainerNamespace in interface ILocatableResource<E>
Returns:
The identifier of the containing resource -or- null if there is no containing resource.

getContainer

public ILocatableResource getContainer()
Return the container.

Returns:
The container -or- null if there is no container.

getTimestamp

public final long getTimestamp()
Description copied from interface: ILocatableResource
The timestamp associated with the view of the resource.

Specified by:
getTimestamp in interface ILocatableResource<E>

getProperties

public final Properties getProperties()
Return an object wrapping the properties specified to the ctor.


getIndexManager

public IIndexManager getIndexManager()
Return the object used to locate indices, relations, and relation containers and to execute operations on those resources.

Returns:
The IIndexManager.

getExecutorService

public final ExecutorService getExecutorService()

toString

public String toString()
The class name, timestamp and namespace for the relation view.

Overrides:
toString in class Object

create

public void create()
Description copied from interface: IMutableResource
Create any logically contained resources (relations, indices).

Specified by:
create in interface IMutableResource<E>
TODO:
Lock service supporting shared locks, leases and lease renewal, excalation of shared locks to exclusive locks, deadlock detection, and possibly a resource hierarchy. Leases should be Callable objects that are submitted by the client to its executor service so that they will renew automatically until cancelled (and will cancel automatically if not renewed).

There is existing code that could be adapted for this purpose. It might have to be adapted to support lock escalation (shared to exclusive), a resource hierarchy, and a delay queue to cancel leases that are not renewed. It would have to be wrapped up as a low-latency service and made available via the IBigdataFederation. It also needs to use a weak reference cache for the collection of resource queues so that they are GC'd rather than growing as new resources are locked and never shrinking.

If we require pre-declaration of locks, then we do not need the dependency graph since deadlocks can only arise with 2PL.

Since the service is remote it should use UUIDs to identify the lock owner(s).

The lock service would be used to bracket operations such as relation create() and destroy() and would be used to prevent those operations while a lease is held by concurrent processes with a shared lock.

Add ctor flag to create iff not found?

There needs to be a lock protocol for subclasses so that they can ensure that they are the only task running create (across the federation) and so that they can release the lock when they are done. The lock can be per the notes above, but the protocol with the subclass will require some coordinating methods.

Full transactions are another way to solve this problem.


destroy

public void destroy()
Description copied from interface: IMutableResource
Destroy any logically contained resources (relations, indices).

Specified by:
destroy in interface IMutableResource<E>

acquireExclusiveLock

protected IResourceLock acquireExclusiveLock()
Acquires an exclusive lock for the getNamespace().

Returns:
the lock.
Throws:
RuntimeException - if anything goes wrong.
See Also:
IResourceLockService

unlock

protected void unlock(IResourceLock resourceLock)
Release the lock.

Parameters:
resourceLock - The lock.

getProperty

protected String getProperty(String localName,
                             String defaultValue)
Resolve the property value using the IIndexManager, the namespace of the resource, and the Properties instance to be tested as hidden parameters.

Parameters:
globalName - The global property name.
defaultValue - The default.
Returns:
The resolved property value.
See Also:
Configuration

getProperty

protected <T> T getProperty(String name,
                            String defaultValue,
                            IValidator<T> validator)
Resolves, parses, and validates the property value.

Parameters:
name - The property name.
defaultValue - The default value.
Returns:


Copyright © 2006-2009 SYSTAP, LLC. All Rights Reserved.