Example #1
0
        /**
         * Gets the current size of all table write queue, number of rows already sended to server, whether a
         * table is being removed, and whether the backgroud thread is returned because of error.
         */
        public BasicTable getAllStatus()
        {
            int                columnNum  = 6;
            List <string>      colNames   = new List <string>(new String[] { "DatabaseName", "TableName", "WriteQueueDepth", "SendedRows", "Removing", "Finished" });
            List <DATA_TYPE>   colTypes   = new List <DATA_TYPE>(new DATA_TYPE[] { DATA_TYPE.DT_STRING, DATA_TYPE.DT_STRING, DATA_TYPE.DT_INT, DATA_TYPE.DT_INT, DATA_TYPE.DT_BOOL, DATA_TYPE.DT_BOOL });
            List <IVector>     columnVecs = new List <IVector>();
            BasicEntityFactory factory    = new BasicEntityFactory();

            for (int i = 0; i < columnNum; ++i)
            {
                columnVecs.Add(factory.createVectorWithDefaultValue(colTypes[i], 0));
            }

            try
            {
                rwLock_.EnterReadLock();
                int rowNum = destTables_.Count();
                foreach (KeyValuePair <Tuple <string, string>, DestTable> t in destTables_)
                {
                    columnVecs[0].add(t.Value.dbName);
                    columnVecs[1].add(t.Value.tableName);
                    columnVecs[2].add(t.Value.writeQueue.Count());
                    columnVecs[3].add(t.Value.sendedRows);
                    columnVecs[4].add(t.Value.destroy);
                    columnVecs[5].add(t.Value.finished);
                }
            }
            finally
            {
                rwLock_.ExitReadLock();
            }
            BasicTable ret = new BasicTable(colNames, columnVecs);

            return(ret);
        }
        List <IVector> createListVector()
        {
            int cols = colTypes_.Count;
            BasicEntityFactory basicEntityFactory = (BasicEntityFactory)BasicEntityFactory.instance();
            List <IVector>     tmp = new List <IVector>();

            for (int i = 0; i < cols; ++i)
            {
                tmp.Add(basicEntityFactory.createVectorWithDefaultValue(colTypes_[i], 0));
            }
            return(tmp);
        }
Example #3
0
 public BasicTable getUnwrittenData(string dbName, string tableName)
 {
     try
     {
         List <IVector>         cols = new List <IVector>();
         List <List <IScalar> > data = new List <List <IScalar> >();
         rwLock_.EnterReadLock();
         if (!destTables_.ContainsKey(Tuple.Create <string, string>(dbName, tableName)))
         {
             throw new Exception("Failed to get unwritten data.Please use addTable to add infomation of database and table first.");
         }
         DestTable destTable = destTables_[Tuple.Create <string, string>(dbName, tableName)];
         int       columns   = destTable.colTypes.Count();
         lock (destTable.failQueue)
         {
             while (destTable.failQueue.Count() != 0)
             {
                 if (destTable.failQueue.TryDequeue(out List <IScalar> queueData))
                 {
                     data.Add(queueData);
                 }
             }
         }
         while (destTable.writeQueue.Count() != 0)
         {
             if (destTable.writeQueue.TryDequeue(out List <IScalar> queueData))
             {
                 data.Add(queueData);
             }
         }
         int size = data.Count();
         BasicEntityFactory factory = new BasicEntityFactory();
         for (int i = 0; i < destTable.colTypes.Count(); ++i)
         {
             IVector vector = factory.createVectorWithDefaultValue(destTable.colTypes[i], size);
             for (int j = 0; j < size; ++j)
             {
                 vector.set(j, data[j][i]);
             }
             cols.Add(vector);
         }
         BasicTable ret = new BasicTable(destTable.colNames, cols);
         return(ret);
     }
     finally
     {
         rwLock_.ExitReadLock();
     }
 }
        public ErrorCodeInfo insertUnwrittenData(List <List <IEntity> > data)
        {
            if (hasError_)
            {
                throw new Exception("Thread is exiting. ");
            }
            BasicEntityFactory basicEntityFactory = (BasicEntityFactory)BasicEntityFactory.instance();
            ErrorCodeInfo      errorCodeInfo      = new ErrorCodeInfo();
            IVector            partitionCol       = basicEntityFactory.createVectorWithDefaultValue(colTypes_[partitionColumnIdx_], data.Count);
            int rows = data.Count;

            for (int i = 0; i < rows; ++i)
            {
                partitionCol.set(i, (IScalar)data[i][partitionColumnIdx_]);
            }

            if (threads_.Count() > 1)
            {
                List <int>         threadindexs = new List <int>();
                BasicEntityFactory factory      = (BasicEntityFactory)BasicEntityFactory.instance();
                if (isPartionedTable_)
                {
                    threadindexs = partitionDomain_.getPartitionKeys(partitionCol);
                }
                else
                {
                    for (int i = 0; i < rows; ++i)
                    {
                        threadindexs.Add(partitionCol.get(i).GetHashCode());
                    }
                }
                for (int i = 0; i < rows; ++i)
                {
                    insertThreadWrite(threadindexs[i], data[i]);
                }
            }
            else
            {
                for (int i = 0; i < rows; ++i)
                {
                    insertThreadWrite(0, data[i]);
                }
            }
            return(new ErrorCodeInfo());
        }
Example #5
0
        private Vector keys(int top)
        {
            BasicEntityFactory factory = new BasicEntityFactory();
            int    size             = Math.Min(top, set.Count);
            Vector keys             = (Vector)factory.createVectorWithDefaultValue(keyType, size);
            IEnumerator <Scalar> it = set.GetEnumerator();
            int count = 0;

            try
            {
                while (count < size)
                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                    keys.set(count++, it.next());
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(keys);
        }
Example #6
0
        public void run()
        {
            List <List <IScalar> > items = new List <List <IScalar> >();

            try
            {
                while (!destTableRawPtr.destroy)
                {
                    items = new List <List <IScalar> >();
                    List <IScalar> item = new List <IScalar>();
                    while ((destTableRawPtr.writeQueue.Count() > 0) && !destTableRawPtr.destroy)
                    {
                        if (!destTableRawPtr.writeQueue.TryDequeue(out item))
                        {
                            continue;
                        }
                        items.Add(item);
                        if (destTableRawPtr.destroy)
                        {
                            throw new Exception("The table " + destTableRawPtr.dbName + " " + destTableRawPtr.tableName + " is destroyed.");
                        }
                    }
                    ;
                    if (items.Count() == 0)
                    {
                        continue;
                    }

                    int                rows    = items.Count();
                    int                cols    = destTableRawPtr.colTypes.Count();
                    List <IVector>     columns = new List <IVector>();
                    BasicEntityFactory factory = new BasicEntityFactory();
                    for (int i = 0; i < cols; ++i)
                    {
                        columns.Add(factory.createVectorWithDefaultValue(destTableRawPtr.colTypes[i], rows));
                    }
                    for (int i = 0; i < rows; ++i)
                    {
                        for (int j = 0; j < cols; ++j)
                        {
                            columns[j].set(i, items[i][j]);
                        }
                    }
                    destTableRawPtr.writeTable = new BasicTable(destTableRawPtr.colNames, columns);

                    List <IEntity> arg = new List <IEntity>();
                    if (!partitioned)
                    {
                        destTableRawPtr.conn.run(destTableRawPtr.createTmpSharedTable);
                    }
                    arg.Add(destTableRawPtr.writeTable);
                    destTableRawPtr.conn.run(destTableRawPtr.tableInsert, arg);
                    destTableRawPtr.sendedRows = destTableRawPtr.sendedRows + rows;
                }
            }
            catch (Exception e)
            {
                if (items != null)
                {
                    destTableRawPtr.finished = true;
                    for (int i = 0; i < items.Count(); ++i)
                    {
                        destTableRawPtr.failQueue.Enqueue(items[i]);
                    }
                }
                Console.WriteLine("Failed to insert data in background thread, with exception: " + e.Message);
            }
            finally
            {
                destTableRawPtr.finished = true;
            }
        }