private void initialize(IList <long?> longs, BasicAnyVector locations) { if (locations.rows() <= 0) { throw new Exception("requires at least one location"); } if (locations.getEntity(0).DataType != Entity_DATA_TYPE.DT_STRING) { throw new Exception("location must be a string"); } if (isSorted(longs) == false) { throw new Exception("ranges " + longs.ToString() + " not sorted!"); } if (longs.Count != locations.rows() + 1) { throw new Exception("expect # locations == # range values - 1"); } ranges = longs.ToArray(); this.locations = new List <>(); bool isScalar = locations.getEntity(0).DataForm == Entity_DATA_FORM.DF_SCALAR; if (isScalar) { for (int i = 0; i < locations.rows(); ++i) { BasicString location = (BasicString)locations.get(i); this.locations.Add(location.String); } } else { for (int i = 0; i < locations.rows(); ++i) { BasicStringVector locationVector = (BasicStringVector)locations.getEntity(i); this.locations.Add(new List <>()); for (int j = 0; j < locationVector.rows(); ++j) { this.locations[this.locations.Count - 1].Add(((BasicString)locationVector.get(j)).String); } } } }
public void Test_ContructBasicTableByDataTable() { DataTable dt = new DataTable(); dt.Columns.Add("dt", Type.GetType("System.DateTime")); dt.Columns.Add("bl", Type.GetType("System.Boolean")); dt.Columns.Add("sb", Type.GetType("System.Byte")); dt.Columns.Add("db", Type.GetType("System.Double")); dt.Columns.Add("ts", Type.GetType("System.TimeSpan")); dt.Columns.Add("i1", Type.GetType("System.Int16")); dt.Columns.Add("i3", Type.GetType("System.Int32")); dt.Columns.Add("i6", Type.GetType("System.Int64")); dt.Columns.Add("s", Type.GetType("System.String")); DataRow dr = dt.NewRow(); dr["dt"] = DBNull.Value; dr["bl"] = DBNull.Value; dr["sb"] = DBNull.Value; dr["db"] = DBNull.Value; dr["ts"] = DBNull.Value; dr["i1"] = DBNull.Value; dr["i3"] = DBNull.Value; dr["i6"] = DBNull.Value; dr["s"] = DBNull.Value; dt.Rows.Add(dr); BasicTable bt = new BasicTable(dt); DBConnection db = new DBConnection(); db.connect(SERVER, PORT); Dictionary <string, IEntity> obj = new Dictionary <string, IEntity>(); obj.Add("up_datatable", (IEntity)bt); db.upload(obj); db.run("share up_datatable as tb1"); BasicStringVector bsv = (BasicStringVector)bt.getColumn(8); Assert.AreEqual("", bsv.get(0).getString()); }
public bool switchServer() { if (!highAvailability) { return(false); } if (controllerHost == null) { return(false); } // 1 find live datanodes and pick one DBConnection tmp = new DBConnection(); tmp.connect(controllerHost, controllerPort); BasicStringVector liveDataNodes = (BasicStringVector)tmp.run("getLiveDataNodes(false)"); tmp.close(); // 2 try get connection to new datanode int size = liveDataNodes.rows(); Console.WriteLine("living node size: " + size); for (int i = 0; i < size; i++) { string[] liveDataNodeSite = liveDataNodes.get(i).getString().Split(':'); hostName = liveDataNodeSite[0]; port = int.Parse(liveDataNodeSite[1]); Console.WriteLine("Try node " + i + ": " + hostName + ":" + port); try { connect(); return(true); } catch (Exception) { } } return(false); }
protected BlockingCollection <List <IMessage> > subscribeInternal(string host, int port, string tableName, string actionName, MessageHandler handler, long offset, bool reconnect, IVector filter, bool createSubInfo) { string topic = ""; IEntity re; BlockingCollection <List <IMessage> > queue; DBConnection dbConn = new DBConnection(); dbConn.connect(host, port); try { string localIP = listeningHost_; if (localIP == null || localIP.Equals(String.Empty)) { localIP = dbConn.LocalAddress; } List <IEntity> @params = new List <IEntity> { new BasicString(tableName), new BasicString(actionName) }; re = dbConn.run("getSubscriptionTopic", @params); topic = ((BasicAnyVector)re).getEntity(0).getString(); @params.Clear(); @params.Add(new BasicString(localIP)); @params.Add(new BasicInt(listeningPort_)); @params.Add(new BasicString(tableName)); @params.Add(new BasicString(actionName)); @params.Add(new BasicLong(offset)); if (filter != null) { @params.Add(filter); } re = dbConn.run("publishTable", @params); lock (subscribeInfos_) { if (createSubInfo) { Site[] sites; if (re is BasicAnyVector) { BasicStringVector HASiteStrings = (BasicStringVector)((BasicAnyVector)re).getEntity(1); int HASiteNum = HASiteStrings.rows(); sites = new Site[HASiteNum]; for (int i = 0; i < HASiteNum; ++i) { String HASite = HASiteStrings.get(i).getString(); String[] HASiteHostAndPort = HASite.Split(':'); String HASiteHost = HASiteHostAndPort[0]; int HASitePort = int.Parse(HASiteHostAndPort[1]); String HASiteAlias = HASiteHostAndPort[2]; sites[i] = new Site(HASiteHost, HASitePort); String HATopic = getTopic(HASiteHost, HASitePort, HASiteAlias, tableName, actionName); HATopicToTrueTopic_[HATopic] = topic; } } else { sites = new Site[] { new Site(host, port) }; lock (HATopicToTrueTopic_) { HATopicToTrueTopic_[topic] = topic; } } SubscribeInfo subscribeInfo = new SubscribeInfo(DateTime.Now, new BlockingCollection <List <IMessage> >(), sites, topic, offset, reconnect, filter, handler, tableName, actionName); subscribeInfo.setConnectState(ConnectState.REQUEST); queue = subscribeInfo.getQueue(); if (subscribeInfos_.ContainsKey(topic)) { throw new Exception("Subscription with topic " + topic + " exist. "); } else { subscribeInfos_.TryAdd(topic, subscribeInfo); } Console.WriteLine("Successfully subscribed table " + topic); } else { SubscribeInfo subscribeInfo = null; if (!subscribeInfos_.TryGetValue(topic, out subscribeInfo)) { throw new Exception("Subscription with topic " + topic + " doesn't exist. "); } lock (subscribeInfo) { if (subscribeInfo.getConnectState() == ConnectState.RECEIVED_SCHEMA) { throw new Exception("Subscription with topic " + topic + " the connection has been created. "); } subscribeInfo.setConnectState(ConnectState.REQUEST); } queue = subscribeInfo.getQueue(); } } } finally { dbConn.close(); } return(queue); }
private void initialize(AbstractVector values, BasicAnyVector locations) { if (values.DataType != Entity_DATA_TYPE.DT_ANY || values.DataForm != Entity_DATA_FORM.DF_VECTOR) { throw new Exception("expect a vector of partitioning lists"); } if (values.rows() <= 0) { throw new Exception("requires at least one partitioning list"); } if (locations.rows() <= 0) { throw new Exception("requires at least one location"); } if (locations.getEntity(0).DataType != Entity_DATA_TYPE.DT_STRING) { throw new Exception("location must be a string"); } if (values.rows() != locations.rows()) { throw new Exception("expect # locations == # partitioning lists"); } this.locationMap = new Dictionary <>(); IList <string>[] locationListArray = new IList[locations.rows()]; bool isScalar = locations.getEntity(0).DataForm == Entity_DATA_FORM.DF_SCALAR; if (isScalar) { for (int i = 0; i < locations.rows(); ++i) { BasicString location = (BasicString)locations.get(i); locationListArray[i] = location.String; } } else { for (int i = 0; i < locations.rows(); ++i) { BasicStringVector locationVector = (BasicStringVector)locations.getEntity(i); locationListArray[i] = new List <>(); for (int j = 0; j < locationVector.rows(); ++j) { BasicString location = (BasicString)locationVector.get(j); locationListArray[i].Add(location.String); } } } for (int i = 0; i < values.rows(); ++i) { AbstractVector partitioningList = (AbstractVector)((BasicAnyVector)values).getEntity(i); if (partitioningList.rows() <= 0) { throw new Exception("expect partitioning list to be nonempty"); } if (partitioningList.DataCategory != Entity_DATA_CATEGORY.INTEGRAL) { throw new Exception("expect partitioning column values to be integral-typed."); } for (int j = 0; j < partitioningList.rows(); ++j) { try { long val = partitioningList.get(j).Number.longValue(); locationMap[val] = locationListArray[i]; } catch (Exception e) { throw new Exception(e); } } } }