Browse Source

Merge pull request #1020 from jakesmith/daligetcount

Add daliadmin count(xpath) feature

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 13 years ago
parent
commit
71c0bf56e7

+ 2 - 2
dali/base/dacoven.cpp

@@ -38,12 +38,12 @@ extern void closedownDFS();
 // base is saved in store whenever block exhausted, so replacement coven servers can restart 
 
 // server side versioning.
-#define ServerVersion    "3.7"
+#define ServerVersion    "3.8"
 #define MinClientVersion "1.5"
 
 
 // client side default versioning.
-static StringAttr ClientVersion("3.4");
+static StringAttr ClientVersion("3.5");
 static StringAttr MinServerVersion("3.1");      // when this upped check initClientProcess instances
 static CDaliVersion _ServerVersion;
 

+ 27 - 0
dali/base/dacsds.cpp

@@ -1925,6 +1925,33 @@ void CClientSDSManager::setConfigOpt(const char *opt, const char *value)
     }
 }
 
+#define MIN_QUERYCOUNT_SVER "3.8"
+unsigned CClientSDSManager::queryCount(const char *xpath)
+{
+    CDaliVersion serverVersionNeeded(MIN_QUERYCOUNT_SVER);
+    if (queryDaliServerVersion().compare(serverVersionNeeded) < 0)
+        throw MakeSDSException(SDSExcpt_VersionMismatch, "Requires dali server version >= " MIN_QUERYCOUNT_SVER " for queryCount(<xpath>)");
+
+    CMessageBuffer mb;
+    mb.append((int)DAMP_SDSCMD_GETCOUNT);
+    mb.append(xpath);
+
+    if (!sendRequest(mb, true))
+        throw MakeSDSException(SDSExcpt_FailedToCommunicateWithServer, ", queryCount(%s)", xpath);
+
+    unsigned count=0;
+    SdsReply replyMsg;    
+    mb.read((int &)replyMsg);
+    if (DAMP_SDSREPLY_OK == replyMsg)
+        mb.read(count);
+    else
+    {
+        assertex(replyMsg == DAMP_SDSREPLY_ERROR);
+        throwMbException("SDS Reply Error ", mb);
+    }
+    return count;
+}
+
 //////////////
 
 ISDSManager &querySDS()

+ 1 - 0
dali/base/dacsds.ipp

@@ -402,6 +402,7 @@ public:
     virtual IPropertyTree &queryProperties() const;
     virtual IPropertyTreeIterator *getElementsRaw(const char *xpath, INode *remotedali, unsigned timeout);
     virtual void setConfigOpt(const char *opt, const char *value);
+    virtual unsigned queryCount(const char *xpath);
 
 private:
     CriticalSection crit;

+ 26 - 0
dali/base/dasds.cpp

@@ -183,6 +183,8 @@ StringBuffer &getSdsCmdText(SdsCommand cmd, StringBuffer &ret)
             return ret.append("DAMP_SDSCMD_GETXPATHSCRITERIA");
         case DAMP_SDSCMD_GETELEMENTSRAW:
             return ret.append("DAMP_SDSCMD_GETELEMENTSRAW");
+        case DAMP_SDSCMD_GETCOUNT:
+            return ret.append("DAMP_SDSCMD_GETCOUNT");
         default:
             return ret.append("UNKNOWN");
     };
@@ -1906,6 +1908,7 @@ public:
     virtual IPropertyTree &queryProperties() const;
     virtual IPropertyTreeIterator *getElementsRaw(const char *xpath,INode *remotedali=NULL, unsigned timeout=MP_WAIT_FOREVER);
     virtual void setConfigOpt(const char *opt, const char *value);
+    virtual unsigned queryCount(const char *xpath);
 
 // ISubscriptionManager impl.
     virtual void add(ISubscription *subs,SubscriptionId id);
@@ -3565,6 +3568,7 @@ int CSDSTransactionServer::run()
                         case DAMP_SDSCMD_GETXPATHSPLUSIDS:
                         case DAMP_SDSCMD_GETEXTVALUE:
                         case DAMP_SDSCMD_GETELEMENTSRAW:
+                        case DAMP_SDSCMD_GETCOUNT:
                         {
                             mb.reset();
                             handler.handleMessage(mb);
@@ -4341,6 +4345,17 @@ void CSDSTransactionServer::processMessage(CMessageBuffer &mb)
                 mb.transferFrom(replyMb);
                 break;
             }
+            case DAMP_SDSCMD_GETCOUNT:
+            {
+                mb.read(xpath);
+                if (queryTransactionLogging())
+                    transactionLog.log("xpath='%s'", xpath.get());
+                CHECKEDDALIREADLOCKBLOCK(manager.dataRWLock, readWriteTimeout);
+                mb.clear();
+                mb.append((int)DAMP_SDSREPLY_OK);
+                mb.append(manager.queryCount(xpath));
+                break;
+            }
             default:
                 assertex(false);
         }
@@ -6811,6 +6826,17 @@ void CCovenSDSManager::setConfigOpt(const char *opt, const char *value)
     queryProperties().setProp(opt, value);
 }
 
+unsigned CCovenSDSManager::queryCount(const char *xpath)
+{
+    unsigned count = 0;
+    if (xpath && *xpath == '/')
+        ++xpath;
+    Owned<IPropertyTreeIterator> iter = root->getElements(xpath);
+    ForEach(*iter)
+        ++count;
+    return count;
+}
+
 void CCovenSDSManager::start()
 {
     server.start();

+ 1 - 0
dali/base/dasds.hpp

@@ -102,6 +102,7 @@ interface ISDSManager
     virtual IPropertyTree &queryProperties() const = 0;
     virtual IPropertyTreeIterator *getElementsRaw(const char *xpath,INode *remotedali=NULL, unsigned timeout=MP_WAIT_FOREVER) = 0;
     virtual void setConfigOpt(const char *opt, const char *value) = 0;
+    virtual unsigned queryCount(const char *xpath) = 0;
 };
 
 extern da_decl const char *queryNotifyHandlerName(IPropertyTree *tree);

+ 1 - 0
dali/base/dasds.ipp

@@ -66,6 +66,7 @@ enum SdsCommand { DAMP_SDSCMD_CONNECT, DAMP_SDSCMD_GET, DAMP_SDSCMD_GETCHILDREN,
                   DAMP_SDSCMD_EDITION, DAMP_SDSCMD_GETSTORE,
                   DAMP_SDSCMD_VERSION, DAMP_SDSCMD_DIAGNOSTIC, DAMP_SDSCMD_GETELEMENTS, DAMP_SDSCMD_MCONNECT, DAMP_SDSCMD_GETCHILDREN2, DAMP_SDSCMD_GET2, DAMP_SDSCMD_GETPROPS,
                   DAMP_SDSCMD_GETXPATHS, DAMP_SDSCMD_GETEXTVALUE, DAMP_SDSCMD_GETXPATHSPLUSIDS, DAMP_SDSCMD_GETXPATHSCRITERIA, DAMP_SDSCMD_GETELEMENTSRAW,
+                  DAMP_SDSCMD_GETCOUNT,
                   DAMP_SDSCMD_MAX,
                   DAMP_SDSCMD_LAZYEXT=0x80000000
                 };

+ 13 - 0
dali/daliadmin/daliadmin.cpp

@@ -71,6 +71,7 @@ void usage(const char *exe)
   printf("  wget <xpath>               -- (gets all matching xpath)\n");
   printf("  add <xpath> <value>        -- adds new value\n");
   printf("  delv <xpath>               -- deletes value\n");
+  printf("  count <xpath>              -- counts xpath matches\n");
   printf("\n");
   printf("Logical File meta information commands:\n");
   printf("  dfsfile <logicalname>          -- get meta information for file\n");
@@ -518,6 +519,14 @@ static void delv(const char *path)
 
 //=============================================================================
 
+static void count(const char *path)
+{
+    unsigned result = querySDS().queryCount(path);
+    OUTLOG("Count of %s is: %d", path, result);
+}
+
+//=============================================================================
+
 static void dfsfile(const char *lname,IUserDescriptor *userDesc, UnsignedArray *partslist=NULL)
 {
     StringBuffer str;
@@ -2245,6 +2254,10 @@ int main(int argc, char* argv[])
                 CHECKPARAMS(1,1);
                 delv(params.item(1));
             }
+            else if (stricmp(cmd,"count")==0) {
+                CHECKPARAMS(1,1);
+                count(params.item(1));
+            }
             else if (stricmp(cmd,"dfsfile")==0) {
                 CHECKPARAMS(1,1);
                 dfsfile(params.item(1),userDesc);