I'm using 4.0.5 and I have to say I really love it! It was the fastest object database I've ever used. But after I ran my codes for 20 more hours and inserted about 300k records, everything went wrong. All methods are throwing exceptions either "An element with the same key already exists" or "one or more errors occurred". I don't know what happened so I delete the database file and restart my program, and after several hours it happened again.
I really don't want to give up stsdb, this is the best object database I know, so I think I really can use some help.
here is my codes using stsdb. Did you see any potential bad code which can cause my problem? BTW, all exceptions was thrown from stsdb dll codes, not my codes, which actually make unable to track it.
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using STSdb4;
using STSdb4.Database;
namespace TiebaUserWorm
{
public class DataPack
{
private IStorageEngine _db;
private ITable<string, Tieba> _tiebaDb;
private ITable<string, BaiduUser> _userDb;
private ITable<Guid, Relation> _relationDb;
public DataPack()
{
_db = STSdb.FromFile(ConfigurationManager.AppSettings["WormDataBasePath"]);
_tiebaDb = _db.OpenXTable<string, Tieba>("Tieba");
_userDb = _db.OpenXTable<string, BaiduUser>("User");
_relationDb = _db.OpenXTable<Guid, Relation>("Relation");
}
public void Store(Tieba ti)
{
_tiebaDb[ti.Name] = ti;
}
public void Store(BaiduUser bu)
{
_userDb[bu.Name] = bu;
}
public void Store(Relation rl)
{
_relationDb[Guid.NewGuid()] = rl;
}
public BaiduUser GetUser(string un)
{
if (_userDb.Exists(un))
{
return _userDb[un];
}
return null;
}
public Tieba GetTieba(string tbn)
{
if (_tiebaDb.Exists(tbn))
{
return _tiebaDb[tbn];
}
return null;
}
public BaiduUser GetNextFanAvailableUser()
{
var res = _userDb.Where(user=>user.Value.UsedForUser == false);
BaiduUser ret = res.FirstOrDefault().Value;
if (ret == null) return null;
ret.UsedForUser = true;
_userDb[ret.Name] = ret;
//_db.Commit();
return ret;
}
public BaiduUser GetNextTiebaAvailableUser()
{
var res = _userDb.Where(user => user.Value.UsedForTieba == false);
BaiduUser ret = res.FirstOrDefault().Value;
if (ret == null) return null;
ret.UsedForTieba = true;
_userDb[ret.Name] = ret;
//_db.Commit();
return ret;
}
public Tieba GetNextAvailableTieba()
{
var res = _tiebaDb.Where(user => user.Value.Used == false);
Tieba ret = res.FirstOrDefault().Value;
if (ret == null) return null;
ret.Used = true;
_tiebaDb[ret.Name] = ret;
//_db.Commit();
return ret;
}
public void Commit()
{
_db.Commit();
}
public void GetDataCount(out long users, out long tiebas, out long relations)
{
users = _userDb.Count();
tiebas = _tiebaDb.Count();
relations = _relationDb.Count();
}
public void Close()
{
_db.Close();
}
}
}