Revert "Revert "Feature/search 1654 (#463)""

This reverts commit 418db22fb8.

This is putting back a previously committed change that broke alfresco-enterprise-repository
This commit is contained in:
Alan Davis
2019-06-01 10:46:41 +01:00
parent 1e276f1889
commit e381052539
7 changed files with 253 additions and 192 deletions

View File

@@ -40,40 +40,42 @@ public interface Node extends NodeIdAndAclId
/** /**
* Helper method to get a key that includes the node and its current version number * Helper method to get a key that includes the node and its current version number
*/ */
public NodeVersionKey getNodeVersionKey(); NodeVersionKey getNodeVersionKey();
/** /**
* Helper method to force the instance to be read-only * Helper method to force the instance to be read-only
*/ */
public void lock(); void lock();
public abstract NodeRef getNodeRef(); NodeRef getNodeRef();
public NodeRef.Status getNodeStatus(QNameDAO qnameDAO); NodeRef.Status getNodeStatus(QNameDAO qnameDAO);
public abstract Pair<Long, NodeRef> getNodePair(); Pair<Long, NodeRef> getNodePair();
/** /**
* Checks the {@link #getTypeQNameId() type} of the node to determine if the node is deleted * Checks the {@link #getTypeQNameId() type} of the node to determine if the node is deleted
* @param qnameDAO DAO to work out type IDs * @param qnameDAO DAO to work out type IDs
* @return <tt>true</tt> if the node is {@link ContentModel#TYPE_DELETED} * @return <tt>true</tt> if the node is {@link ContentModel#TYPE_DELETED}
*/ */
public abstract boolean getDeleted(QNameDAO qnameDAO); boolean getDeleted(QNameDAO qnameDAO);
public abstract Long getVersion(); Long getVersion();
public abstract StoreEntity getStore(); StoreEntity getStore();
public abstract String getUuid(); String getUuid();
public abstract Long getTypeQNameId(); Long getTypeQNameId();
public abstract Long getLocaleId(); Long getLocaleId();
public abstract TransactionEntity getTransaction(); TransactionEntity getTransaction();
public abstract AuditablePropertiesEntity getAuditableProperties(); AuditablePropertiesEntity getAuditableProperties();
public abstract String getShardKey(); String getShardKey();
Integer getExplicitShardId();
} }

View File

@@ -56,6 +56,7 @@ public class NodeEntity implements Node, PermissionCheckValue, Serializable, Clo
private TransactionEntity transaction; private TransactionEntity transaction;
private AuditablePropertiesEntity auditableProperties; private AuditablePropertiesEntity auditableProperties;
private String shardKey; private String shardKey;
private Integer explicitShardId;
/** /**
* Required default constructor * Required default constructor
@@ -342,10 +343,22 @@ public class NodeEntity implements Node, PermissionCheckValue, Serializable, Clo
return this.shardKey; return this.shardKey;
} }
@Override
public Integer getExplicitShardId()
{
return this.explicitShardId;
}
public synchronized void setShardKey(String shardKey) public synchronized void setShardKey(String shardKey)
{ {
this.shardKey = shardKey; this.shardKey = shardKey;
} }
public synchronized void setExplicitShardId(Integer explicitShardId)
{
this.explicitShardId = explicitShardId;
}
} }

View File

@@ -25,28 +25,44 @@
*/ */
package org.alfresco.repo.index.shard; package org.alfresco.repo.index.shard;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.Set; import java.util.Set;
import org.alfresco.service.cmr.search.SearchParameters; import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.util.Pair;
/** /**
* @author Andy * A registry which collects all the active shard subscriptions.
* *
* @author Andy
* @author agazzarini
* @author eporciani
*/ */
public interface ShardRegistry public interface ShardRegistry
{ {
public void registerShardState(ShardState shardState); /**
* Registers (or updates the existing subscription) of a shard.
*
* @param shardState the shard state, which contains the information about the shard that wants to subscribe/register.
*/
void registerShardState(ShardState shardState);
public List<ShardInstance> getIndexSlice(SearchParameters searchParameters); List<ShardInstance> getIndexSlice(SearchParameters searchParameters);
public void purge(); void purge();
public HashMap<Floc, HashMap<Shard, HashSet<ShardState>>> getFlocs(); Map<Floc, Map<Shard, Set<ShardState>>> getFlocs();
public void purgeAgedOutShards(); void purgeAgedOutShards();
/**
* Returns the shard instance (i.e. shard number) which owns (or should own) the transaction associated with the given timestamp.
*
* @param coreId an identifier (e.g. core name, base url) of the core / collection whose requested shard belongs to.
* @param txnTimestamp the transaction timestamp used as search criteria.
* @return the shard instance (i.e. shard number) which owns (or should own) the transaction associated with the given timestamp.
*/
OptionalInt getShardInstanceByTransactionTimestamp(String coreId, long txnTimestamp);
} }

View File

@@ -57,6 +57,7 @@ public class NodeParameters
private Set<QName> excludeAspects; private Set<QName> excludeAspects;
private String shardProperty; private String shardProperty;
private String coreName;
public int getMaxResults() public int getMaxResults()
{ {
@@ -192,4 +193,14 @@ public class NodeParameters
{ {
this.shardProperty = shardProperty; this.shardProperty = shardProperty;
} }
public String getCoreName() {
return this.coreName;
}
public void setCoreName(String coreName){
this.coreName = coreName;
}
} }

View File

@@ -36,6 +36,7 @@ import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.OptionalInt;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.zip.CRC32; import java.util.zip.CRC32;
@@ -46,6 +47,7 @@ import org.alfresco.repo.dictionary.DictionaryDAO;
import org.alfresco.repo.domain.node.Node; import org.alfresco.repo.domain.node.Node;
import org.alfresco.repo.domain.node.NodeDAO; import org.alfresco.repo.domain.node.NodeDAO;
import org.alfresco.repo.domain.node.NodeDAO.ChildAssocRefQueryCallback; import org.alfresco.repo.domain.node.NodeDAO.ChildAssocRefQueryCallback;
import org.alfresco.repo.domain.node.NodeEntity;
import org.alfresco.repo.domain.permissions.AclDAO; import org.alfresco.repo.domain.permissions.AclDAO;
import org.alfresco.repo.domain.qname.QNameDAO; import org.alfresco.repo.domain.qname.QNameDAO;
import org.alfresco.repo.domain.solr.SOLRDAO; import org.alfresco.repo.domain.solr.SOLRDAO;
@@ -375,6 +377,15 @@ public class SOLRTrackingComponentImpl implements SOLRTrackingComponent
for (Node node : nodes) for (Node node : nodes)
{ {
if (shardRegistry != null){
shardRegistry.getShardInstanceByTransactionTimestamp(
nodeParameters.getCoreName(),
node.getTransaction().getCommitTimeMs()).ifPresent(
shardId -> ((NodeEntity) node).setExplicitShardId(shardId));
}
callback.handleNode(node); callback.handleNode(node);
} }
} }

View File

@@ -26,6 +26,7 @@
<result property="id" column="id" jdbcType="BIGINT" javaType="java.lang.Long"/> <result property="id" column="id" jdbcType="BIGINT" javaType="java.lang.Long"/>
<result property="typeQNameId" column="type_qname_id" jdbcType="BIGINT" javaType="java.lang.Long" /> <result property="typeQNameId" column="type_qname_id" jdbcType="BIGINT" javaType="java.lang.Long" />
<result property="transaction.id" column="txn_id" jdbcType="BIGINT" javaType="java.lang.Long"/> <result property="transaction.id" column="txn_id" jdbcType="BIGINT" javaType="java.lang.Long"/>
<result property="transaction.commitTimeMs" column="txn_commit_time_ms" jdbcType="BIGINT" javaType="java.lang.Long"/>
<result property="aclId" column="acl_id" jdbcType="BIGINT" javaType="java.lang.Long"/> <result property="aclId" column="acl_id" jdbcType="BIGINT" javaType="java.lang.Long"/>
<result property="store.protocol" column="protocol" jdbcType="VARCHAR" javaType="java.lang.String"/> <result property="store.protocol" column="protocol" jdbcType="VARCHAR" javaType="java.lang.String"/>
<result property="store.identifier" column="identifier" jdbcType="VARCHAR" javaType="java.lang.String"/> <result property="store.identifier" column="identifier" jdbcType="VARCHAR" javaType="java.lang.String"/>
@@ -117,6 +118,7 @@
COALESCE(np.long_value, node.id) as id, COALESCE(np.long_value, node.id) as id,
node.type_qname_id as type_qname_id, node.type_qname_id as type_qname_id,
node.transaction_id as txn_id, node.transaction_id as txn_id,
txn.commit_time_ms as txn_commit_time_ms,
node.uuid as uuid, node.uuid as uuid,
node.acl_id as acl_id, node.acl_id as acl_id,
store.protocol as protocol, store.protocol as protocol,

View File

@@ -139,4 +139,10 @@ class TestNode implements Node
return null; return null;
} }
@Override
public Integer getExplicitShardId()
{
return null;
}
} }