我不知道发生了什么事有时cassandra很容易提交帖子并在~20ms内存储数据,而其他时间帖子需要~120000ms但是帖子没有提交(即存储)。任何建议伙伴我两天都在努力解决这个问题 我在bellow查询中没有发现任何错误。我索引了已检查的列。
这是我的主要应用文件:
var express=require('express'),
app=express(),
morgan=require('morgan'),
bodyParser=require('body-parser'),
methodOverride=require('method-override'),
cookieParser=require('cookie-parser'),
sessions=require('express-session'),
passport=require('passport'),
path=require('path'),
cassandra=require('node-cassandra-cql'),
port=3000;
var cassandraSettings=require('./config/cassandra').setting;
cassandraClient = new cassandra.Client(cassandraSettings);
cassandraClient.connect(function(error){
if(error)
console.log('error - ' + error);
else
console.log('Logged In to Cassandra');
});
var cassandraConfig={
readConsistency:cassandra.types.consistencies.one,
writeConsistency:cassandra.types.consistencies.any,
cassandra:cassandra,
cassandraClient:cassandraClient
}
require('./config/passport')(passport,cassandraConfig);
app.use(morgan('dev'))
.use(bodyParser())
.use(methodOverride())
.use(cookieParser())
.use(sessions({name:"sid",cookie:{maxAge:1000*60*60*24*30},secret:"Ankit"}))
.use(passport.initialize())
.use(passport.session());
//url for statics
app.use('/static', express.static(__dirname + '/views'));
require('./routes/login')(app,passport);
require('./routes/signup')(app,passport);
//Used to insert Sport, League, TeamDetails
require('./routes/private/insert_sport_detail')(app,cassandraConfig);
//require('./routes/private/insert_league_detail')(app,cassandraConfig);
app.listen(port);
我的cassandra route.js:
var queries={
insert:{
sport_detail:{
query:'INSERT INTO only_sport_detail(sportid,sport_name,sport_short_name,time_made,checked) VALUES (?,?,?,?,?)'
},
league_detail:{
query:'INSERT INTO only_league_detail(leagueid,league_name,league_short_name,league_abbreviation,league_location,time_made,checked) VALUES (?,?,?,?,?,?,?)'
}
},
retrieve:{
sport_detail:{
query:'SELECT * FROM only_sport_detail WHERE checked=?'
},
league_detail:{
query:'SELECT * FROM only_league_detail WHERE checked=?'
}
}
};
module.exports=function(app,cassandraConfig){
var cassandraClient=cassandraConfig.cassandraClient;
var writeConsistency=cassandraConfig.writeConsistency;
var readConsistency=cassandraConfig,readConsistency;
var cassandra=cassandraConfig.cassandra;
app.get('/insert/detail/sport',function(req,res){
res.sendfile('views/insert/sport_detail.html');
});
app.post('/insert/detail/sport',function(req,res){
sportid=cassandra.types.timeuuid();
cassandraClient.executeAsPrepared(
queries.insert.sport_detail.query,
[sportid,req.body.sport_name,req.body.sport_short_name,{value: new Date(), hint: cassandra.types.dataTypes.timestamp},1],
writeConsistency,
function(err){
if(!err)
{
cassandraClient.executeAsPrepared(
queries.retrieve.sport_detail.query,
[1],
function(err,result){
if(err)
{
console.log(err);
res.send('Sorry error');
res.end();
}
else
{
res.json(result.rows);
res.end();
}
}
);
}
}
);
});
app.get('/get/detail/sport',function(req,res){
cassandraClient.executeAsPrepared(
queries.retrieve.sport_detail.query,
[1],
function(err,result){
if(err)
{
console.log(err);
res.send('Sorry error');
res.end();
}
else
{
res.json(result.rows);
res.end();
}
}
);
});
};