diff --git a/src/main/java/org/alfresco/repo/domain/node/Node.java b/src/main/java/org/alfresco/repo/domain/node/Node.java
index b034651ff7..7eea53f676 100644
--- a/src/main/java/org/alfresco/repo/domain/node/Node.java
+++ b/src/main/java/org/alfresco/repo/domain/node/Node.java
@@ -1,28 +1,28 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco 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 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco 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 Alfresco. If not, see .
- * #L%
- */
+/*
+ * #%L
+ * Alfresco Repository
+ * %%
+ * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * %%
+ * This file is part of the Alfresco software.
+ * If the software was purchased under a paid Alfresco license, the terms of
+ * the paid license agreement will prevail. Otherwise, the software is
+ * provided under the following open source license terms:
+ *
+ * Alfresco 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco 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 Alfresco. If not, see .
+ * #L%
+ */
package org.alfresco.repo.domain.node;
import org.alfresco.model.ContentModel;
@@ -40,40 +40,42 @@ public interface Node extends NodeIdAndAclId
/**
* 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
*/
- 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 getNodePair();
+ Pair getNodePair();
/**
* Checks the {@link #getTypeQNameId() type} of the node to determine if the node is deleted
* @param qnameDAO DAO to work out type IDs
* @return true 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();
-
- public abstract String getShardKey();
+ AuditablePropertiesEntity getAuditableProperties();
+
+ String getShardKey();
+
+ Integer getExplicitShardId();
}
\ No newline at end of file
diff --git a/src/main/java/org/alfresco/repo/domain/node/NodeEntity.java b/src/main/java/org/alfresco/repo/domain/node/NodeEntity.java
index eb12b0c25d..afdc9c2a51 100644
--- a/src/main/java/org/alfresco/repo/domain/node/NodeEntity.java
+++ b/src/main/java/org/alfresco/repo/domain/node/NodeEntity.java
@@ -1,28 +1,28 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco 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 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco 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 Alfresco. If not, see .
- * #L%
- */
+/*
+ * #%L
+ * Alfresco Repository
+ * %%
+ * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * %%
+ * This file is part of the Alfresco software.
+ * If the software was purchased under a paid Alfresco license, the terms of
+ * the paid license agreement will prevail. Otherwise, the software is
+ * provided under the following open source license terms:
+ *
+ * Alfresco 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco 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 Alfresco. If not, see .
+ * #L%
+ */
package org.alfresco.repo.domain.node;
import java.io.Serializable;
@@ -54,8 +54,9 @@ public class NodeEntity implements Node, PermissionCheckValue, Serializable, Clo
private Long localeId;
private Long aclId;
private TransactionEntity transaction;
- private AuditablePropertiesEntity auditableProperties;
+ private AuditablePropertiesEntity auditableProperties;
private String shardKey;
+ private Integer explicitShardId;
/**
* Required default constructor
@@ -90,7 +91,7 @@ public class NodeEntity implements Node, PermissionCheckValue, Serializable, Clo
this.localeId = node.getLocaleId();
this.aclId = node.getAclId();
this.transaction = node.getTransaction();
- this.auditableProperties = node.getAuditableProperties();
+ this.auditableProperties = node.getAuditableProperties();
this.shardKey = node.getShardKey();
}
@@ -139,7 +140,7 @@ public class NodeEntity implements Node, PermissionCheckValue, Serializable, Clo
.append(", localeId=").append(localeId)
.append(", aclId=").append(aclId)
.append(", transaction=").append(transaction)
- .append(", auditProps=").append(auditableProperties)
+ .append(", auditProps=").append(auditableProperties)
.append(", shardKey=").append(shardKey)
.append("]");
return sb.toString();
@@ -334,18 +335,30 @@ public class NodeEntity implements Node, PermissionCheckValue, Serializable, Clo
{
checkLock();
this.auditableProperties = auditableProperties;
- }
-
- @Override
- public String getShardKey()
- {
- return this.shardKey;
- }
-
- public synchronized void setShardKey(String shardKey)
- {
- this.shardKey = shardKey;
- }
-
-
+ }
+
+ @Override
+ public String getShardKey()
+ {
+ return this.shardKey;
+ }
+
+ @Override
+ public Integer getExplicitShardId()
+ {
+ return this.explicitShardId;
+ }
+
+ public synchronized void setShardKey(String shardKey)
+ {
+ this.shardKey = shardKey;
+ }
+
+ public synchronized void setExplicitShardId(Integer explicitShardId)
+ {
+ this.explicitShardId = explicitShardId;
+ }
+
+
+
}
diff --git a/src/main/java/org/alfresco/repo/index/shard/ShardRegistry.java b/src/main/java/org/alfresco/repo/index/shard/ShardRegistry.java
index 04034074c2..6e8295e795 100644
--- a/src/main/java/org/alfresco/repo/index/shard/ShardRegistry.java
+++ b/src/main/java/org/alfresco/repo/index/shard/ShardRegistry.java
@@ -1,52 +1,68 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco 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 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco 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 Alfresco. If not, see .
- * #L%
- */
+/*
+ * #%L
+ * Alfresco Repository
+ * %%
+ * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * %%
+ * This file is part of the Alfresco software.
+ * If the software was purchased under a paid Alfresco license, the terms of
+ * the paid license agreement will prevail. Otherwise, the software is
+ * provided under the following open source license terms:
+ *
+ * Alfresco 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco 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 Alfresco. If not, see .
+ * #L%
+ */
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.Map;
+import java.util.Optional;
+import java.util.OptionalInt;
import java.util.Set;
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 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 getIndexSlice(SearchParameters searchParameters);
+ List getIndexSlice(SearchParameters searchParameters);
- public void purge();
+ void purge();
- public HashMap>> getFlocs();
+ Map>> 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);
}
diff --git a/src/main/java/org/alfresco/repo/solr/NodeParameters.java b/src/main/java/org/alfresco/repo/solr/NodeParameters.java
index e01c0b753d..f78c69d012 100644
--- a/src/main/java/org/alfresco/repo/solr/NodeParameters.java
+++ b/src/main/java/org/alfresco/repo/solr/NodeParameters.java
@@ -1,28 +1,28 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco 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 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco 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 Alfresco. If not, see .
- * #L%
- */
+/*
+ * #%L
+ * Alfresco Repository
+ * %%
+ * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * %%
+ * This file is part of the Alfresco software.
+ * If the software was purchased under a paid Alfresco license, the terms of
+ * the paid license agreement will prevail. Otherwise, the software is
+ * provided under the following open source license terms:
+ *
+ * Alfresco 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco 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 Alfresco. If not, see .
+ * #L%
+ */
package org.alfresco.repo.solr;
import java.util.List;
@@ -54,10 +54,11 @@ public class NodeParameters
private Set excludeNodeTypes;
private Set includeAspects;
- private Set excludeAspects;
-
- private String shardProperty;
+ private Set excludeAspects;
+ private String shardProperty;
+ private String coreName;
+
public int getMaxResults()
{
return maxResults;
@@ -181,15 +182,25 @@ public class NodeParameters
public void setExcludeAspects(Set excludeAspects)
{
this.excludeAspects = excludeAspects;
- }
-
- public String getShardProperty()
- {
- return this.shardProperty;
- }
-
- public void setShardProperty(String shardProperty)
- {
- this.shardProperty = shardProperty;
}
+
+ public String getShardProperty()
+ {
+ return this.shardProperty;
+ }
+
+ public void setShardProperty(String shardProperty)
+ {
+ this.shardProperty = shardProperty;
+ }
+
+ public String getCoreName() {
+ return this.coreName;
+ }
+
+ public void setCoreName(String coreName){
+ this.coreName = coreName;
+ }
+
+
}
diff --git a/src/main/java/org/alfresco/repo/solr/SOLRTrackingComponentImpl.java b/src/main/java/org/alfresco/repo/solr/SOLRTrackingComponentImpl.java
index ac845a5685..fe1041a5ba 100644
--- a/src/main/java/org/alfresco/repo/solr/SOLRTrackingComponentImpl.java
+++ b/src/main/java/org/alfresco/repo/solr/SOLRTrackingComponentImpl.java
@@ -36,6 +36,7 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.OptionalInt;
import java.util.Set;
import java.util.TreeSet;
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.NodeDAO;
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.qname.QNameDAO;
import org.alfresco.repo.domain.solr.SOLRDAO;
@@ -375,6 +377,15 @@ public class SOLRTrackingComponentImpl implements SOLRTrackingComponent
for (Node node : nodes)
{
+ if (shardRegistry != null){
+ shardRegistry.getShardInstanceByTransactionTimestamp(
+ nodeParameters.getCoreName(),
+ node.getTransaction().getCommitTimeMs()).ifPresent(
+ shardId -> ((NodeEntity) node).setExplicitShardId(shardId));
+
+ }
+
+
callback.handleNode(node);
}
}
diff --git a/src/main/resources/alfresco/ibatis/org.alfresco.repo.domain.dialect.Dialect/solr-common-SqlMap.xml b/src/main/resources/alfresco/ibatis/org.alfresco.repo.domain.dialect.Dialect/solr-common-SqlMap.xml
index 07d33988f4..c7744bc5fc 100644
--- a/src/main/resources/alfresco/ibatis/org.alfresco.repo.domain.dialect.Dialect/solr-common-SqlMap.xml
+++ b/src/main/resources/alfresco/ibatis/org.alfresco.repo.domain.dialect.Dialect/solr-common-SqlMap.xml
@@ -26,6 +26,7 @@
+
@@ -115,12 +116,13 @@