Commit 4bead4a6 authored by Angel Borroy's avatar Angel Borroy

Find minimum and maximum transaction commit time for a Node Id range.

parent 0200a573
......@@ -30,25 +30,26 @@ import org.mybatis.spring.SqlSessionTemplate;
/**
* iBatis-specific extension of the Node abstract DAO
*
* Includes additional operations to default NodeDATImpl
* Includes additional operations to default NodeDAOImpl
*
* @author aborroy
*
*/
public class ExtendedNodeDAOImpl extends NodeDAOImpl
{
// Entry id in node-extended-SqlMap.xml
// Entry ids in node-extended-SqlMap.xml
private static final String SELECT_TXN_MIN_TX_ID_IN_NODE_IDRANGE = "alfresco.node.select_TxnMinTxIdInNodeIdRange";
private static final String SELECT_TXN_MAX_TX_ID_IN_NODE_IDRANGE = "alfresco.node.select_TxnMaxTxIdInNodeIdRange";
private SqlSessionTemplate template;
/**
* Gets commit time for the minimum transaction id for a node id range.
* fromNodeId < toNodeId
* Gets the minimum commit time from transactions including a node id
* in the range [fromNodeId:toNodeId]
*
* @param fromNodeId Initial node id
* @param toNodeId Final node id
* @return transaction Id
* @return minimum commit time
*/
public Long getMinTxInNodeIdRange(Long fromNodeId, Long toNodeId)
{
......@@ -59,6 +60,23 @@ public class ExtendedNodeDAOImpl extends NodeDAOImpl
return template.selectOne(SELECT_TXN_MIN_TX_ID_IN_NODE_IDRANGE, nodeRangeEntity);
}
/**
* Gets the maximum commit time from transactions including a node id
* in the range [fromNodeId:toNodeId]
*
* @param fromNodeId Initial node id
* @param toNodeId Final node id
* @return maximum commit time
*/
public Long getMaxTxInNodeIdRange(Long fromNodeId, Long toNodeId)
{
NodeRangeEntity nodeRangeEntity = new NodeRangeEntity();
nodeRangeEntity.setFromNodeId(fromNodeId);
nodeRangeEntity.setToNodeId(toNodeId);
return template.selectOne(SELECT_TXN_MAX_TX_ID_IN_NODE_IDRANGE, nodeRangeEntity);
}
public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate)
{
this.template = sqlSessionTemplate;
......
......@@ -34,14 +34,14 @@ import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Returns the commit time of the minimum transaction id for a node id range.
* Returns the minimum and the maximum commit time for transactions in a node id range.
* This webscript is used by Shards using DB_ID_RANGE in order to
* identify the first transaction that needs to be indexed.
* identify the transaction time window that needs to be indexed.
*
* @author aborroy
*
*/
public class MinTransactionGet extends DeclarativeWebScript
public class TransactionIntervalGet extends DeclarativeWebScript
{
private ExtendedNodeDAOImpl nodeDAO;
......@@ -56,7 +56,8 @@ public class MinTransactionGet extends DeclarativeWebScript
Long toNodeId = Long.parseLong(req.getParameter("toNodeId"));
Map<String, Object> model = new HashMap<>();
model.put("transactionCommitTimeMs", nodeDAO.getMinTxInNodeIdRange(fromNodeId, toNodeId));
model.put("minTransactionCommitTimeMs", nodeDAO.getMinTxInNodeIdRange(fromNodeId, toNodeId));
model.put("maxTransactionCommitTimeMs", nodeDAO.getMaxTxInNodeIdRange(fromNodeId, toNodeId));
return model;
}
......
{
"transactionCommitTimeMs": <#if transactionCommitTimeMs??>${transactionCommitTimeMs?c}<#else>-1</#if>
}
\ No newline at end of file
<webscript>
<shortname>Get the commit time of the minimum transaction id in a range of node ids</shortname>
<shortname>Get the minimum and the maximum commit times for transactions in a range of node ids</shortname>
<description>
Get the commint time of the minimum transaction id in a range of node ids: [fromNodeId TO toNodeId]
If the nodes doesn't exist in the repository, -1 is returned
Get the minimum and the maximum commit times for transactions in a range of node ids: [fromNodeId TO toNodeId]
If the nodes don't exist in the repository, -1 is returned in both fields.
</description>
<url>/api/solr/minTransaction?fromNodeId={fromNodeId}&amp;toNodeId={toNodeId}</url>
<url>/api/solr/transactionInterval?fromNodeId={fromNodeId}&amp;toNodeId={toNodeId}</url>
<format default="json">argument</format>
<!-- Solr api is protected by a solr-specific authentication mechanism -->
<authentication>none</authentication>
......
{
"minTransactionCommitTimeMs": <#if minTransactionCommitTimeMs??>${minTransactionCommitTimeMs?c}<#else>-1</#if>,
"maxTransactionCommitTimeMs": <#if maxTransactionCommitTimeMs??>${maxTransactionCommitTimeMs?c}<#else>-1</#if>
}
\ No newline at end of file
......@@ -5,8 +5,8 @@
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- /api/solr webscript returning the min txId in a nodeId range -->
<bean id="webscript.org.alfresco.repository.solr.minTransaction.get"
class="org.alfresco.repo.web.scripts.solr.MinTransactionGet"
<bean id="webscript.org.alfresco.repository.solr.transactionInterval.get"
class="org.alfresco.repo.web.scripts.solr.TransactionIntervalGet"
parent="webscript">
<property name="nodeDAO" ref="extendedNodeDAO" />
</bean>
......
......@@ -22,4 +22,22 @@
)
</select>
<select id="select_TxnMaxTxIdInNodeIdRange" resultType="java.lang.Long">
select
commit_time_ms
from
alf_transaction
where
id =
(
select
max(transaction_id)
from
alf_node
where
id &gt;= #{fromNodeId}
and id &lt;= #{toNodeId}
)
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment