Appfabric caching for database dependency - appfabric

We believe the AppFabric caching is a good fit for the caching requirement. However, we also want to implement some sort of database dependency, i.e. the cache should sync with the backend database asynchronously. The read-through and write behind feature seems interesting, could anyone please help point us a direction how can we leverage these features in achieving the auto sync behavior between the appfabric and database? Thanks a lot!

SqlDependency can be used to notify to your application about modifications in database. To use this you need to enable service broker on database level, please go through these limitation before implementation this solution
using (SqlConnection connection = new SqlConnection(yourConnectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand(databaseSqlToBeMonitered, connection))
{
SqlDependency dependency = new SqlDependency(command);
dependency.OnChange += new OnChangeEventHandler((a, b) =>
{
//Remove data from cache
});
command.ExecuteReader().Close();
}
}

Related

How to prioritize queries from different user roles in superset?

I have low-priority users and high-priority users. First of all, I need to process queries from high-priority users. Low-priority users should be limited initially because they slow down the high-priority users.
At the moment I have not found a solution. Is this generally possible or do I need to fork apache-superset and implement such logic myself in the source code? Is this functionality planned in the roadmap?
Superset generally is a thin layer over your existing data stores and doesn't have much of a compute layer.
With this in mind, the right technical decision is probably to configure this at the database / data store layer. Many people integrate LDAP both into Superset and into their data store so 2-way configuration of roles & datas tore priorities / permissions can be configured.
With that being said, Superset is open source! You're definitely welcome to fork the code and implement it yourself. Better yet, you can feel free to raise a discussion by creating a Github issue.
Like Srini said, it depends on your data layer.
One way you could this is by defining a custom SQL_QUERY_MUTATOR in your superset_config.py:
# superset_config.py
def SQL_QUERY_MUTATOR(sql, username, security_manager):
pool = "vip" if username in VIP_LIST else "normal"
return f"-- pool: {pool}\n{sql}"
This will prepend a comment to the query specifying a pool that's either "vip" or "normal". You could then send this to a proxy that parses the comment and dispatches the query to the proper header.
Another way of doing this is specifying a DB_CONNECTION_MUTATOR that sets connection parameters depending on the user:
# superset_config.py
def DB_CONNECTION_MUTATOR(uri, params, username, security_manager, source):
pool = "vip" if username in VIP_LIST else "normal"
params["configuration"] = {"job.queue.name": pool}}
return uri, params

PouchDb Local database size

We are developing an app in ionic3 which use PouchDB and CouchDB. We would like to launch on mid February but we are worry if the database grow too much I make run out of memory in device.
To test we'd like to insert thousands records and check database size.. here we have the problem. We can't find out how get local db size.
I was diving in PouchDB documentation and I only found how to get info about remote database size but not local. I think remote size needs not to be equal than local. Anyone have an idea?
Thanks
I found a partial solution, it is partial because it only works in android, chrome and firefox but not in ios and safari. I get used and available storage with this
calculaEspacio(){
let nav: any = navigator;
nav.storage.estimate().then((obj)=>{
this.usado=Math.round(((obj.usage/1048576)*100))/100;
this.total = Math.round(((obj.quota/1048576)*100))/100;
})}
Anyone know equivalent for webkit?
Example
npm install pouchdb pouchdb-size
//index.js
var PouchDB = require('pouchdb');
PouchDB.plugin(require('pouchdb-size'));
var db = new PouchDB('test');
db.installSizeWrapper();
db.info().then(function (resp) {
//resp will contain disk_size
})
pouchdb-size https://github.com/pouchdb/pouchdb-size
Build Status Dependency Status devDependency Status
Adds disk_size to info()'s output for your *down backed PouchDB's.
Tested with leveldown, sqldown, jsondown, locket and medeadown. When it can't determine the database size, it falls back to the default info() output.
Full informations here
If you're using Ionic 3, I guess you can use the SQLite Plugin to have unlimited data

How to change users while preserving the store?

I want to implement a "fast login".
I'm developing an enterprise software where a lot of users work in the same organization with the same data in the same computer and I want to be able to know who did what and when. Right now they have to log out and log in and load the data has to be loaded into the store all over again.
What I want is for them to be able to, without logging out, click on a user, from the organization, insert his password and the user is switched while preserving the store.
Any idea how I can accomplish this?
I'm using ember-simple-auth v1.1.0 and ember v2.10.2
The simpliest solution would be disabling page reload when user logs out. As far as I know, it's a reload causes data loss from store, not a logging out by itself. To do this, you need to overwrite sessionInvalidated method in your application route. For example,
sessionInvalidated() {
this.transitionTo('/login');
},
But remember - you lower security with this method: if someone will log out and leave webpage with app open, other person will have a possibility to extract data (if they have enough technical background to at least install ember inspector).
Other solution will require heavy research. I think it should be possible to implement custom authenticator which would allow to authenticate new user without logging out previous, by simply replacing tokens in store. But I don't know how hard it will be to implement and what obstacles you can meet. You will need to read ember-simple-auth's sources a lot, that's for sure.
I was actually able to solve it by simply using authenticate() with another user but never calling invalidateSession() which is the function that calls sessionInvalidated() that looks like this:
sessionInvalidated() {
if (!testing) {
if (this.get('_isFastBoot')) {
this.transitionTo(Configuration.baseURL);
} else {
window.location.replace(Configuration.baseURL);
}
}
}
So by not calling sessionInvalidated() the user isn't redirected or the page refreshed and the new user is able to keep using the store without switching pages.

Camunda History and Audit Event Log, I can't query any history data

I have been running Camunda with MariaDB, it's a good solution
but I have a problem, I saw the Camunda User Guide that describes History and Audit Event Log, so I write some codes as follows:
List historyList = historyService.createHistoricProcessInstanceQuery().finished().processDefinitionId("Sample1").list();
int historySize = historyList.size();
LOGGER.info("historyList size=" + historySize);
I have finished the Sample1 Process, but the historySize still is zero, I think I lost some configuration, how can I do?
Wnat's difference between Runtime Database and Histort Database? do I need to install two Databases?
Thank you
I solved the Problem by using processDefinitionKey
I passed processDefinitionKey to processDefinitionId, no wonder it can't get all finished instances of a process
I can get all finished instances of a process using correct processDefinitionId or processDefinitionKey

How to change client schema during provisioning?

I'm rushing (never a good thing) to get Sync Framework up and running for a "offline support" deadline on my project. We have a SQL Express 2008 instance on our server and then will deploy SQLCE to the clients. Clients will only sync with server, no peer-to-peer.
So far I have the following working:
Server schema setup
Scope created and tested
Server provisioned
Client provisioned w/ table creation
I've been very impressed with the relative simplicity of all of this. Then I realized the following:
Schema created through client provisioning to SQLCE does not setup default values for uniqueidentifier types.
FK constraints are not created on client
Here is the code that is being used to create the client schema (pulled from an example I found somewhere online)
static void Provision()
{
SqlConnection serverConn = new SqlConnection(
"Data Source=xxxxx, xxxx; Database=xxxxxx; " +
"Integrated Security=False; Password=xxxxxx; User ID=xxxxx;");
// create a connection to the SyncCompactDB database
SqlCeConnection clientConn = new SqlCeConnection(
#"Data Source='C:\SyncSQLServerAndSQLCompact\xxxxx.sdf'");
// get the description of the scope from the SyncDB server database
DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(
ScopeNames.Main, serverConn);
// create CE provisioning object based on the scope
SqlCeSyncScopeProvisioning clientProvision = new SqlCeSyncScopeProvisioning(clientConn, scopeDesc);
clientProvision.SetCreateTableDefault(DbSyncCreationOption.CreateOrUseExisting);
// starts the provisioning process
clientProvision.Apply();
}
When Sync Framework creates the schema on the client I need to make the additional changes listed earlier (default values, constraints, etc.).
This is where I'm getting confused (and frustrated):
I came across a code example that shows a SqlCeClientSyncProvider that has a CreatingSchema event. This code example actually shows setting the RowGuid property on a column which is EXACTLY what I need to do. However, what is a SqlCeClientSyncProvider?! This whole time (4 days now) I've been working with SqlCeSyncProvider in my sync code. So there is a SqlCeSyncProvider and a SqlCeClientSyncProvider?
The documentation on MSDN is not very good in explaining what either of these.
I've further confused whether I should make schema changes at provision time or at sync time?
How would you all suggest that I make schema changes to the client CE schema during provisioning?
SqlCeSyncProvider and SqlCeClientSyncProvider are different.
The latter is what is commonly referred to as the offline provider and this is the provider used by the Local Database Cache project item in Visual Studio. This provider works with the DbServerSyncProvider and SyncAgent and is used in hub-spoke topologies.
The one you're using is referred to as a collaboration provider or peer-to-peer provider (which also works in a hub-spoke scenario). SqlCeSyncProvider works with SqlSyncProvider and SyncOrchestrator and has no corresponding Visual Studio tooling support.
both providers requires provisioning the participating databases.
The two types of providers provisions the sync objects required to track and apply changes differently. The SchemaCreated event applies to the offline provider only. This get's fired the first time a sync is initiated and when the framework detects that the client database has not been provisioned (create user tables and the corresponding sync framework objects).
the scope provisioning used by the other provider dont apply constraints other than the PK. so you will have to do a post-provisioning step to apply the defaults and constraints yourself outside of the framework.
While researching solutions without using SyncAgent I found that the following would also work (in addition to my commented solution above):
Provision the client and let the framework create the client [user] schema. Now you have your tables.
Deprovision - this removes the restrictions on editing the tables/columns
Make your changes (in my case setting up Is RowGuid on PK columns and adding FK constraints) - this actually required me to drop and add a column as you can't change the "Is RowGuid" property an existing columns
Provision again using DbSyncCreationOption.CreateOrUseExisting