Which size should I use to find out if I'm getting close to the storage limit on my Lite plan - cloudant

When I query cloudant for database info, there are a number of sizes returned:
I have:
let db = require('nano')(IBMdburl);
let nano = require('nano')(IBMurl);
Then if I invoke:
nano.request({ db: 'wxd', path: '/_design/app/_info' })
.then(body => {
console.log('got design doc info', body);
})
I get following sizes:
view_index: {
...
sizes: { file: 451178400, external: 510408846, active: 273442954 },
...
}
and for the database info:
db.info()
.then(body => {
console.log('got database info', body);
})
the following:
sizes: { file: 914744004, external: 294471620, active: 747430633 },
Which sizes should I use to know how close I am to the 1GB Lite plan limit?

Related

Error connect to Spring-boot-Rsocket (Auth JWT) from web-client RSocketWebSocketClient

The connection to server with spring-boot client works good:
public RSocketAdapter() throws IOException {
requester = createRSocketRequesterBuilder()
.connectWebSocket(URI.create("ws://localhost:7878/"))
.block();
}
private RSocketRequester.Builder createRSocketRequesterBuilder() {
RSocketStrategies strategies = RSocketStrategies.builder()
.encoders(encoders -> encoders.add(new Jackson2CborEncoder()))
.decoders(decoders -> decoders.add(new Jackson2CborDecoder()))
.dataBufferFactory(new NettyDataBufferFactory(PooledByteBufAllocator.DEFAULT))
.build();
return RSocketRequester.builder().rsocketStrategies(strategies);
}
public Mono<HelloToken> signIn(String principal, String credential) {
return requester
.route("signin.v1")
.data(HelloUser.builder().userId(principal).password(credential).build())
.retrieveMono(HelloToken.class)
.doOnNext(token -> {
accessToken = token.getAccessToken();
})
.onErrorStop();
}
And server receives such frame:
Correct byte frame
But the same request from web-client:
authSocketReactiv = () => {
const maxRSocketRequestN = 2147483647;
const keepAlive = 60000;
const lifetime = 180000;
const dataMimeType = 'application/json';
const metadataMimeType = 'message/x.rsocket.authentication.bearer.v0';
var client = new RSocketClient({
serializers: {
data: JsonSerializer,
metadata: JsonSerializer,
},
setup: {
dataMimeType,
keepAlive,
lifetime,
metadataMimeType
},
transport: new RSocketWebSocketClient({
url: 'ws://localhost:7878'
},Encoders)
});
// Open the connection
client.connect().subscribe({
onComplete: socket => {
socket.requestStream({
data:{
'user_id': '0000',
'password': 'Zero4'
},
metadata:'signin.v1'
}).subscribe({
onComplete: () => console.log('complete'),
onError: error => {
console.log(error);
},
onNext: payload => {
console.log('Subscribe1');
},
onSubscribe: subscription => {
console.log('Subscribe');
subscription.request(2147483647);
},
});
},
onError: error => {
console.log(error);
},
onSubscribe: cancel => {
}
});
Forms the incorrect frame and fall with “metadata is malformed ERROR” :
Error byte frame from web
What encoding or buffering options should be used here? Thanks for any tips and suggestions.
You are likely going to want to work with composite metadata and set your metadataMimeType to MESSAGE_RSOCKET_COMPOSITE_METADATA.string.
The important bit is going to be the routing metadata, which is what tells the server how to route the incoming RSocket request.
I haven't dug through the server example code you linked on StackOverflow, but just by looking at your example code, you would supply the routing metadata with your requestStream as so:
Also, the example project you listed though references signin as a request/response so you actually don't want requestStream, but requestResponse.
socket
.requestResponse({
data: Buffer.from(JSON.stringify({
user_id: '0000',
password: 'Zero4'
})),
metadata: encodeCompositeMetadata([
[MESSAGE_RSOCKET_ROUTING, encodeRoute("signin.v1")],
]),
})
You will likely want to use BufferEncoders, as shown in this example. And additionally, I believe you should not use JsonSerializer for the metadata, but instead IdentitySerializer, which will pass the composite metadata buffer straight through, rather than trying to serialize to and from JSON.
You may still run into some issues, but I suspect that this will get you past the metadata is malformed ERROR error.
Hope that helps.
Grate thanks for the detailed advices. According to directions, this complined solution works for my case:
getAuthToken = () => {
const maxRSocketRequestN = 2147483647;
const keepAlive = 60000;
const lifetime = 180000;
const dataMimeType = APPLICATION_JSON.string;
const metadataMimeType = MESSAGE_RSOCKET_COMPOSITE_METADATA.string;
var client = new RSocketClient({
serializers: {
data: IdentitySerializer,
metadata: IdentitySerializer,
},
setup: {
dataMimeType,
keepAlive,
lifetime,
metadataMimeType
},
transport: new RSocketWebSocketClient({
url: 'ws://localhost:7878'
},BufferEncoders)
});
client.connect().then(
(socket) => {
socket.requestResponse({
data: Buffer.from(JSON.stringify({
user_id: '0000',
password: 'Zero4'
})),
metadata: encodeCompositeMetadata([
[MESSAGE_RSOCKET_ROUTING, encodeRoute("signin.v1")],
]),
}).subscribe({
onComplete: (data) => console.log(data),
onError: error =>
console.error(`Request-stream error:${error.message}`),
});
},
(error) => {
console.log("composite initial connection failed");
}
);

RSocket error 0x201 (APPLICATION_ERROR): readerIndex(1) + length(102) exceeds writerIndex(8): UnpooledSlicedByteBu

setInterval(() => {
let that = this;
this.socket && this.socket.requestResponse({
data: '' + (++index),
metadata: 'org.mvnsearch.account.AccountService.findById',
}).subscribe({
onComplete(payload) {
let account = JSON.parse(payload.data);
that.setState({
nick: account.nick
})
},
onError: (e) => {
console.log('onError', e)
}
});
}, 2000)
trying to connect to spring rsocket using reactjs. getting an error before subscribe in the javascript code shown below.
**this.socket.requestResponse({
data: '' + (++index),
metadata: 'org.mvnsearch.account.AccountService.findById',
})**
How to resolve the above issue?
If you are using rsocket routing on the backend, it is length prefixed. See https://github.com/rsocket/rsocket-demo/blob/master/src/main/js/app.js#L22-L36
// Create an instance of a client
const client = new RSocketClient({
setup: {
keepAlive: 60000,
lifetime: 180000,
dataMimeType: 'application/json',
metadataMimeType: 'message/x.rsocket.routing.v0',
},
transport: new RSocketWebSocketClient({url: url}),
});
const stream = Flowable.just({
data: '{"join": {"name": "Web"}}',
metadata: String.fromCharCode('chat/web'.length) + 'chat/web',
});
The routing specification allows multiple routes, so the encoding of a single route is unfortunately complicated by this. https://github.com/rsocket/rsocket/blob/master/Extensions/Routing.md

On saving entity PrimaryGeneratedColumn value not generated, gives NOT NULL constraint error

Typeorm 0.2.8
I'm building an Ionic app for both mobile use and browser (PWA) use. Below is some shortened code from my project. I create a simple entity with a PrimaryGeneratedColumn and try to insert one instance. This generates an error about the primary column being NULL. Doesn't the word 'generated' mean the column value gets generated?
Is this a bug? Something specific to the sqljs driver? Or something obvious and simple I missed?
Entity
#Entity()
export class MyEntity {
#PrimaryGeneratedColumn()
id:number;
#Column()
name:string;
#CreateDateColumn()
createdAt:string;
}
Migration
export class Migration20181022133900 implements MigrationInterface {
async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.createTable(new Table({
name: 'my_entity',
columns: [
{
name: 'id',
type: 'int',
isPrimary: true,
isGenerated: true
},
{
name: 'name',
type: 'varchar'
},
{
name: 'createdAt',
type: 'timestamp',
'default': 'now()'
}
]
}), true);
}
async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.dropTable('my_entity');
}
}
Database provider
const DATABASE_SHARED_OPTIONS:Partial<ConnectionOptions> = {
entities: [
MyEntity
],
logging: 'all',
logger: new DatabaseLogger(),
migrationsRun: true,
migrations: [
Migration20181022133900
]
};
#Injectable()
export class Database {
constructor(public platform:Platform) {}
setup(): Promise<Connection> {
let options: CordovaConnectionOptions | SqljsConnectionOptions;
// Mobile app
if (this.platform.is('cordova')) {
options = {
type: 'cordova',
database: 'my_project.db',
location: 'default',
};
options = Object.assign(options, DATABASE_SHARED_OPTIONS);
}
// Browser PWA app
else {
options = {
type: 'sqljs',
autoSave: true,
location: 'my_project',
};
options = Object.assign(options, DATABASE_SHARED_OPTIONS);
}
return createConnection(options);
}
}
App component
export class MyApp {
constructor(
platform: Platform,
database: Database
) {
platform.ready().then(() => {
database.setup()
.then((connection) => {
this.insertTest();
});
});
}
insertTest() {
const myEntity= new MyEntity();
myEntity.name = 'foo';
getRepository(MyEntity).save(myEntity)
.then((data) => {
console.log(data); // never reached due to error
});
}
}
The database log show the following query (with parameters ["foo"]):
INSERT INTO "my_entity"("name", "createdAt") VALUES (?, datetime('now'))
The following error shows up in my console:
ERROR Error: Uncaught (in promise): QueryFailedError: NOT NULL constraint failed: my_entity.id
Update 1
It only seems to give the error when using migrations. Removing the migrations and using synchronize: true on the database setting works and generates an id for the entity. So is there something wrong with my column definition in the migration code?
{
name: 'id',
type: 'int',
isPrimary: true,
isGenerated: true
}
Update 2
Okay, I fixed it. The migration configuration for a #PrimaryGeneratedColumn seems to be very specific. For anyone else facing this issue, this fixed it for me:
{
name: 'id',
type: 'integer', // instead of 'int', required for the increment strategy
isPrimary: true,
isGenerated: true,
generationStrategy: 'increment' // thought this was the default
}
Okay, I fixed it. The migration configuration for a #PrimaryGeneratedColumn seems to be very specific. For anyone else facing this issue, this fixed it for me:
{
name: 'id',
type: 'integer', // instead of 'int', required for the increment strategy
isPrimary: true,
isGenerated: true,
generationStrategy: 'increment' // thought this was the default
}

How to configure sequelize with mssql?

I want to connect with Microsoft Sql using sequelize. I found this link http://docs.sequelizejs.com/manual/installation/getting-started.html
and i wrote the code below with nodejs:
require('dotenv').config();
var express = require('express');
var app = express();
const Sequelize = require('sequelize');
const sequelize = new Sequelize(process.env.DB_NAME,null,null, {
dialect: 'mssql',
host: process.env.DB_HOST + "\\" + process.env.DB_SERVER,
operatorsAliases: false,
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
}
});
sequelize.authenticate().then((err) => {
console.log('Connection successful', err);
})
.catch((err) => {
console.log('Unable to connect to database', err);
});
app.listen(process.env.PORT);
console.log('Starting Server on Port ', process.env.PORT);
But when I run the code i have an error:
sequelize deprecated String based operators are now deprecated. Please use
Symbol based operators for better security, read more at
http://docs.sequelizejs.com/manual/tutorial/querying.html#operators
node_modules\sequelize\lib\sequelize.js:242:13
Unable to connect to database { SequelizeHostNotFoundError: Failed to
connect to USER-PC\SQLEXPRESS:1433-getaddrinfo ENOTFOUND USER-PC\SQLEXPRESS
at Connection.connection.on.err (C:\Users\User\Desktop\loginApp\node_modules
\sequelize\lib\dialects\mssql\connection-manager.js:98:22)
what i did wrong and i cant connect to database ?
// You can do it with a string.
const Sequelize = require('sequelize');
const sequelize = new Sequelize("mssql://username:password#mydatabase.database.windows.net:1433",
{ pool: {
"max": 10,
"min": 0,
"idle": 25000,
"acquire": 25000,
"requestTimeout": 300000
},
dialectOptions: {
options: { encrypt: true }
}
});
// This uses the Raw Query to query for all dbs for example
sequelize.query(`
SELECT name, database_id, create_date
FROM sys.databases
GO `,
{ type: sequelize.QueryTypes.SELECT})
.then(async dbs => {
console.log("dbs", dbs);
return dbs;
});```
Example above: mssql db hosted on Azure.
Example below: mssql db on localhost.
You can do it with key value pairs or a string.
`
var Sequelize = require("sequelize");
var sequelize = new Sequelize("sequelize_db_name", user, password, {
host: "localhost",
port: 1433,
dialect: "mssql",
pool: {
max: 5,
min: 0,
idle: 10000
},
dialectOptions: {
options: { encrypt: true }
}
});`
ES6 format
import { Sequelize } from "sequelize";
import dotenv from 'dotenv';
dotenv.config();
const db = new Sequelize(
process.env.DB_NAME,
process.env.DB_USER,
process.env.DB_PASS,
{
host: process.env.DB_HOST,
dialect: "mssql",
}
);
export default db;
You need to provide mysql database name, username and password for database
var sequelize= new Sequelize('your Database name', 'username', 'password', {
host: 'localhost',
dialect: 'mssql', //postgres'|'sqlite'|''|'mysql',
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
// SQLite only
//storage: 'path/to/database.sqlite'
});
If you are still looking for an answer, here is what worked for me for Azure mssql. Please replace the username, password and server name. Replace the database with the name of database if you want to connect to a specific database within it, else remove it
const sequelize = new Sequelize("mssql://username:password#mydatabase.database.windows.net:1433/database", {
dialect: 'mssql',
dialectOptions: {
// Observe the need for this nested `options` field for MSSQL
options: {
// Your tedious options here
useUTC: false,
dateFirst: 1
}
}
});

azure mobile services calling sql server stored procedure and get a requestTimeout 15000ms error

I keep getting this error:
{"name":"RequestError","message":"Timeout: Request failed to complete in 15000ms","code":"ETIMEOUT","number":"ETIMEOUT","precedingErrors":[]}
How do I increase the timeout for my request?
I am not sure if this is coming from the sql server database or from the node.js service?
How do I see what is happening with sql server from azure?
I have sql server management studio and visual studio so i can login to my database, but don't see how to increase timeout etc.
Are there any parameters I set in node.js to increase timeout?
I found this:
http://azure.github.io/azure-mobile-apps-node/global.html#dataConfiguration
and presume I have to set something in my query object?
My node.js API that I call, searchService.js
var HttpStatus = require('http-status-codes');
module.exports = {
"post": function (req, res, next) {
var resultSet = {
TotalRecords: 0,
Results: null
};
var parameters = [
{ name: 'forumId', value: req.body.forumId },
{ name: 'registrantId', value: req.body.registrantId },
{ name: 'userId', value: req.azureMobile.user.id },
{ name: 'exclusive', value: req.body.exclusive },
{ name: 'type', value: req.body.type },
{ name: 'categoryIds', value: req.body.categoryIds.join(",") },
{ name: 'locationIds', value: req.body.locationIds.join(",") },
{ name: 'unitIds', value: req.body.unitIds.join(",") },
{ name: 'priceIds', value: req.body.priceIds.join(",") },
{ name: 'delimiter', value: "," }
];
console.log("parameters = " + JSON.stringify(parameters));
var query = {
sql: "exec SearchServicesStrictTotal #forumId, #registrantId, #userId, #exclusive, #type, #categoryIds, #locationIds, #unitIds, #priceIds, #delimiter",
parameters: parameters
};
req.azureMobile.data.execute(query)
.then(function(result) {
console.log("got result " + JSON.stringify(result));
resultSet.TotalRecords = result[0].Total;
res.status(HttpStatus.OK).send(resultSet);
}).catch(function(error){
console.log("error one " + JSON.stringify(error));
res.status(HttpStatus.BAD_REQUEST).send(error);
});
}
};
The default for request timeout is 15000 ms. To increase the timeout for the request you could try to put this to your app.js file.
var mobileApp = azureMobileApps({
homePage: true,
data: {
requestTimeout: 60000
}
});
The app.js file will look like this.
var express = require('express'),
azureMobileApps = require('azure-mobile-apps');
var app = express();
var mobileApp = azureMobileApps({
homePage: true,
data: {
requestTimeout: 60000
}
});
mobileApp.tables.import('./tables');
mobileApp.api.import('./api');
mobileApp.tables.initialize()
.then(function () {
app.use(mobileApp); // Register the Azure Mobile Apps middleware
app.listen(process.env.PORT || 3000); // Listen for requests
});
Hope it helps.

Resources