I have a tiny groovy script to run .mongo file against a replica set of Mongo DB ver. 3.6:
ScriptOperations scriptOps = new MongoTemplate( mongoClient, 'mydb' ).scriptOps()
[ 'inx.mongo', 'roles.mongo' ].each{
try{
ExecutableMongoScript s = new ExecutableMongoScript( new File( it ).text )
def res = scriptOps.execute s
log.info "processed $it >> $res"
}catch( Throwable t ){
log.error "$it --> $t"
}
}
When the script is run, I'm getting the log:
10:22:23.017 [main] INFO Migrator - processed inx.mongo >> [retval:[createdCollectionAutomatically:false, numIndexesBefore:4, numIndexesAfter:4, note:all indexes already exist, ok:1.0, operationTime:Timestamp{value=6608816253102456876, seconds=1538734942, inc=44}, $clusterTime:[clusterTime:Timestamp{value=6608816253102456876, seconds=1538734942, inc=44}, signature:[hash:org.bson.types.Binary#c98f581, keyId:0]]], ok:1.0, operationTime:Timestamp{value=6608816253102456876, seconds=1538734942, inc=44}, $clusterTime:[clusterTime:Timestamp{value=6608816253102456876, seconds=1538734942, inc=44}, signature:[hash:org.bson.types.Binary#c98f581, keyId:0]]]
10:22:23.087 [main] ERROR Migrator - roles.mongo --> com.mongodb.MongoCommandException: Command failed with error 139: 'Error: Waiting for replication not allowed while holding a lock :
_getErrorWithCode#src/mongo/shell/utils.js:25:13
DB.prototype.updateRole#src/mongo/shell/db.js:1713:19
#:1:1
' on server mozaiq_mongo2_1:27002. The full response is { "operationTime" : { "$timestamp" : { "t" : 1538734942, "i" : 44 } }, "ok" : 0.0, "errmsg" : "Error: Waiting for replication not allowed while holding a lock :\n_getErrorWithCode#src/mongo/shell/utils.js:25:13\nDB.prototype.updateRole#src/mongo/shell/db.js:1713:19\n#:1:1\n", "code" : 139, "codeName" : "JSInterpreterFailure", "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1538734942, "i" : 44 } }, "signature" : { "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" }, "keyId" : { "$numberLong" : "0" } } } }
So the 1st file inx.mongo seems to be processed fine, but the 2nd one roles.mongo throws the Error: Waiting for replication not allowed while holding a lock.
How can I fix the issue?
Related
It's been a while I've worked with Flink, but I cannot seem to get a simple CEP program to working. For reference, I connected to a local port and typed numbers. Reading the docs and trying many samples (most of them old) I've still not found an answer.
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(1);
DataStream<Integer> source = env.socketTextStream("localhost", 3030, "\n")
.map((MapFunction<String, Integer>) s -> Integer.parseInt(s) * 2);
Pattern<Integer, ?> alarmPattern = Pattern.<Integer>begin("first")
.where(new SimpleCondition<Integer>() {
#Override
public boolean filter(Integer value) throws Exception {
System.out.println("Is it match? " + value);
return value < 30;
}
});
PatternStream<Integer> pattern = CEP.pattern(source, alarmPattern);
pattern.process(new PatternProcessFunction<Integer, Object>() {
#Override
public void processMatch(Map<String, List<Integer>> map, Context
context, Collector<Object> collector) throws Exception {
System.out.println("Detected Pattern: " + map);
}
});
source.print();
env.execute();
Above code connects to localhost 3030, and parses strings and multiplies them by 2. I verified that one is working by printing them. But neither pattern is processing, or the simple condition is being invoked at all. Looking at the execution plan (removing print), I see there is indeed a CEP operator:
{
"nodes" : [ {
"id" : 1,
"type" : "Source: Socket Stream",
"pact" : "Data Source",
"contents" : "Source: Socket Stream",
"parallelism" : 1
}, {
"id" : 2,
"type" : "Map",
"pact" : "Operator",
"contents" : "Map",
"parallelism" : 1,
"predecessors" : [ {
"id" : 1,
"ship_strategy" : "FORWARD",
"side" : "second"
} ]
}, {
"id" : 4,
"type" : "GlobalCepOperator",
"pact" : "Operator",
"contents" : "GlobalCepOperator",
"parallelism" : 1,
"predecessors" : [ {
"id" : 2,
"ship_strategy" : "HASH",
"side" : "second"
} ]
} ]
}
I'm using Mongodb 4 with spring boot 2.1.0-M4
The follwing code works locally on my computer, but fails at dev environment:
#Transactional
public void registerNewUser(UserRegistrationForm registrationForm)
throws IllegalArgumentException {
validator.validate(registrationForm);
User user = new User();
user.setEmail(registrationForm.email);
user.setPassword(encoder.encode(registrationForm.password));
user.setEnabled(false);
user.setGroups(Sets.newHashSet(ClientRoles.USER));
User saved = userRepository.save(user);
registrationService.sendInvitation(user.getEmail());
}
With the following error:
com.mongodb.MongoCommandException: Command failed with error 40527 (Location40527): 'Unable to persist transaction state because the session transaction collection is missing. This indicates that the config.transactions collection has been manually deleted.' on server mongodb-1-servers-vm-0:27017. The full response is { "operationTime" : { "$timestamp" : { "t" : 1540422989, "i" : 1 } }, "ok" : 0.0, "errmsg" : "Unable to persist transaction state because the session transaction collection is missing. This indicates that the config.transactions collection has been manually deleted.", "code" : 40527, "codeName" : "Location40527", "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1540422994, "i" : 1 } }, "signature" : { "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" }, "keyId" : { "$numberLong" : "0" } } } } at
I have no idea what I should try debugging, or what to try, both databases are of the same version and have replica sets initialized. Any help is appreciated.
Actually, the error is pretty self explanatory. It seems that for some reason transactions collection from dev environment db was deleted. The fix is straightforward:
use config
db.createCollection("transactions",{})
I search through the half of the Internet but found either nothing or outdated solutions with db.eval(). Hence my question.
I have some code using mongo driver 3.5.0:
MongoDatabase db = mongoClient.getDatabase 'mydb'
println db.runCommand( new BasicDBObject( eval:'db.version()' ) )
Exception in thread "main" com.mongodb.MongoCommandException: Command failed with error 13: 'not authorized on mydb to execute command { eval: "db.version()", $readPreference: { mode: "secondaryPreferred" }, $db: "mydb" }' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "not authorized on mydb to execute command { eval: \"db.version()\", $readPreference: { mode: \"secondaryPreferred\" }, $db: \"mydb\" }", "code" : 13, "codeName" : "Unauthorized" }
at com.mongodb.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:115)
at com.mongodb.connection.CommandProtocol.execute(CommandProtocol.java:107)
I can run this command in the shell:
mongo "mongodb://admin:admin#somehost:27003/mydb?replicaSet=myset" -eval 'db.version()'
outputs
3.6.6
If I run the command from inside the shell:
db.runCommand( { 'eval':'db.version()' } )
I'm also getting
{
"operationTime" : Timestamp(1536931496, 11),
"ok" : 0,
"errmsg" : "not authorized on mydb to execute command { eval: \"db.version()\", $db: \"mydb\" }",
"code" : 13,
"codeName" : "Unauthorized"
}
The user I'm connecting with looks like:
{
"_id" : "mydb.admin",
"user" : "admin",
"db" : "mydb",
"roles" : [
{
"role" : "readWrite",
"db" : "mydb"
},
{
"role" : "dbAdmin",
"db" : "mydb"
},
{
"role" : "userAdmin",
"db" : "mydb"
},
{
"role" : "dbOwner",
"db" : "mydb"
}
]
}
What am I missing?
Do I need special privileges for eval?
As per mongodb documentation, you need a role that grants anyAction on AnyResource.
i am doin Amazon Stack Creation through Java Eclipse.
tis below line of code is throwing the error
csr.setTemplateURL("https://s3.amazonaws.com/cloudformation-templates-us-east- 1/AutoScalingMultiAZSample.template");
I am getting the error as :
Caught Exception: Parameters: [KeyName] must have values (Service: AmazonCloudFormation; Status Code: 400; Error Code: ValidationError; Request ID: 9363d711-3535-11e4-8cf2-913ef42879cb)
Reponse Status Code: 400
my json template url is
https://s3.amazonaws.com/cloudformation-templates-us-east-1/AutoScalingMultiAZSample.template
Please help on this to detect the exact source of the error.
Ok i tried to validate your json schema using online validator.
http://jsonlint.com/
I just copied your json schema and pasted there. It said invalid schema expecting { on line 1. Ok for sure i have to put opening and closing brackets and in between your schema. But again it gave error. Extra Bracket } on last line. So i had to remove it. And then json schema was validated. It means somewhere in your schema you are putting an extra closing bracket }.
I think the place where you are making mistake is:
"InstanceSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "Enable SSH access and HTTP from the load balancer only",
"SecurityGroupIngress" : [ {
"IpProtocol" : "tcp",
"FromPort" : "22",
"ToPort" : "22",
"CidrIp" : { "Ref" : "SSHLocation"}
},
{
"IpProtocol" : "tcp",
"FromPort" : { "Ref" : "WebServerPort" },
"ToPort" : { "Ref" : "WebServerPort" },
"SourceSecurityGroupOwnerId" : {"Fn::GetAtt" : ["ElasticLoadBalancer", "SourceSecurityGroup.OwnerAlias"]},
"SourceSecurityGroupName" : {"Fn::GetAtt" : ["ElasticLoadBalancer", "SourceSecurityGroup.GroupName"]}
} ]
}
}//Extra Bracket i think so
},
"Outputs" : {
"URL" : {
"Description" : "The URL of the website",
"Value" : { "Fn::Join" : [ "", [ "http://", { "Fn::GetAtt" : [ "ElasticLoadBalancer", "DNSName" ]}]]}
}
}
}
I am using MongoDB latest version 2.12 Java Driver, in Eclipse. However, even after extensive searching on SO as well as Google, I could not resolve my problem.
Here is my code snippet:
mongoClient_m = new MongoClient();
db_m = mongoClient_m.getDB("atlascompare");
coll_m = db_m.getCollection("CollRMOB");
BasicDBObject doc = new BasicDBObject("ErrorName", "RMOB RULE_INFO")
.append("ErrorCause", "Database Out Of Sync")
.append("Resolution", "Try clearing your cache, or check database ver")
.append("TechnicalDat", new BasicDBObject("Java Null Pointer", 203).append("Java File Not Found Exception", 102));
coll_m.insert(doc);
doc = new BasicDBObject("ErrorName", "ERROR X_2609")
.append("ErrorCause", "CAUSE X_2609")
.append("Resolution", "PERFORM X_2609")
.append("TechnicalDat", new BasicDBObject("Java X_2609_1", 203).append("Java X_2609_2", 102));
coll_m.insert(doc);
doc = new BasicDBObject("ErrorName", "ERROR Y_2609")
.append("ErrorCause", "CAUSE Y_2609")
.append("Resolution", "PERFORM Y_2609")
.append("TechnicalDat", new BasicDBObject("Java Y_2609_1", 203).append("Java Y_2609_2", 102));
coll_m.insert(doc);
Here is the output I get on printing the docs:
{ "_id" : { "$oid" : "53e306577bdc3279309da4e3"} , "ErrorName" : "RMOB RULE_INFO" , "ErrorCause" : "Database Out Of Sync" , "Resolution" : "Try clearing your cache, or check database ver" , "TechnicalDat" : { "Java Null Pointer" : 203 , "Java File Not Found Exception" : 102}}
{ "_id" : { "$oid" : "53e306577bdc3279309da4e4"} , "ErrorName" : "ERROR X_2609" , "ErrorCause" : "CAUSE X_2609" , "Resolution" : "PERFORM X_2609" , "TechnicalDat" : { "Java X_2609_1" : 203 , "Java X_2609_2" : 102}}
{ "_id" : { "$oid" : "53e306577bdc3279309da4e5"} , "ErrorName" : "ERROR Y_2609" , "ErrorCause" : "CAUSE Y_2609" , "Resolution" : "PERFORM Y_2609" , "TechnicalDat" : { "Java Y_2609_1" : 203 , "Java Y_2609_2" : 102}}
However a simple text search does not show any output!!
BasicDBObject textSearch = new BasicDBObject("$text", "ERROR X_2609");
BasicDBObject search = new BasicDBObject("$search", textSearch);
System.out.println(coll_m.find(search));
Prints the following lines:
Cursor id=0, ns=atlascompare.CollRMOB, query={ "$search" : { "$text" : "ERROR X_2609"}}, numIterated=0, readPreference=primary
Can anybody please guide me what I am doing wrong?!
Edit 1: Also, I made sure the indexes were made. Here is the output when I print the indexes:
Indexes present ----------------------------
{ "v" : 1 , "key" : { "_id" : 1} , "name" : "_id_" , "ns" : "atlascompare.CollRMOB"}
{ "v" : 1 , "key" : { "_fts" : "text" , "_ftsx" : 1} , "name" : "$**_text" , "ns" : "atlascompare.CollRMOB" , "weights" : { "$**" : 1} , "default_language" : "english" , "language_override" : "language" , "textIndexVersion" : 2}
It looks to me that your query is not correct.
The query should look like: (in the MongoDB Shell)
db.CollRMOB.find( { $text : { $search : "ERROR X_2609" } } );
So in your Java code it should be something like:
BasicDBObject textSearch = new BasicDBObject("$search", "ERROR X_2609");
BasicDBObject search = new BasicDBObject("$text", textSearch);
// the print the documents
System.out.println(coll_m.find(search).toArray() );
Tug