Quantcast
Channel: Mobile - Couchbase Forums
Viewing all 1117 articles
Browse latest View live

Delete database configuration vi Admin REST API


CBL sync and Android PIE?

$
0
0

@DougWhitehead wrote:

Sync seems to work using the Emulator with Android Studio. However, when I deploy the app to the Android PIE hardware device, I seem to be getting a failure to connect. It would appear that the handheld is “Unauthorized”.

I’ve played with the proxy settings on the handheld, and it if I mis-type the proxy it shows an unknown host type of error. So the proxy server seems to be recognizable. So, for what ever reason, my android app uses a sync that is failing to be authorized to do a sync.

It reminds me somewhat of the sort of behavior I started to see when using Android PIE to access an un-secured server. In that example, I had to change the default for the app to allow such a thing to go forward (namely set android:usesCleartextTraffic to “true” in the AndroidManifest.xml file).

I believe the Sync Gateway is not locked down. Is there a similar setting needed for a socket connection in Android PIE? A sample of the failure to connect run log is below

E/CouchbaseLite/NETWORK: CBLWebSocket.socket_open()
W/CouchbaseLite/NETWORK: WebSocketListener.onFailure() response -> Response{protocol=http/1.0, code=401, message=Unauthorized, url=http://couchbase-gateway.dev.ims-mobile-data.ssaeim.prod.us.walmart.net:4984/common/_blipsync}: java.net.ProtocolException: Expected HTTP 101 response but was ‘401 Unauthorized’
W/CouchbaseLite/NETWORK: {N8litecore4repl12C4SocketImplE#1}==> N8litecore4repl12C4SocketImplE ws://couchbase-gateway.dev.ims-mobile-data.ssaeim.prod.us.walmart.net:4984/common/_blipsync @0x70cbc4e130
{N8litecore4repl12C4SocketImplE#1} WebSocket closed abnormally with status 401
W/CouchbaseLite/NETWORK: C4Socket.dispose() handle -> 484455014976
E/CouchbaseLite/REPLICATOR: {Repl#2}==> N8litecore4repl10ReplicatorE /data/user/0/com.walmart.ims.puddle/files/common.cblite2/ ->ws://couchbase-gateway.dev.ims-mobile-data.ssaeim.prod.us.walmart.net:4984/common/_blipsync @0x70b8537dc8
E/CouchbaseLite/REPLICATOR: {Repl#2} Got LiteCore error: WebSocket error 401 “Unauthorized”
W/CouchbaseLite/NETWORK: C4Socket.open() socket -> 484425436608
C4Socket.open() clazz -> com.couchbase.lite.internal.replicator.CBLWebSocket
E/CouchbaseLite/NETWORK: CBLWebSocket.socket_open()
W/CouchbaseLite/NETWORK: WebSocketListener.onFailure() response -> Response{protocol=http/1.0, code=502, message=Bad Gateway, url=http://couchbase-gateway.dev.ims-mobile-data.ssaeim.prod.us.walmart.net:4984/salesfloor/_blipsync}: java.net.ProtocolException: Expected HTTP 101 response but was ‘502 Bad Gateway’
W/CouchbaseLite/NETWORK: {N8litecore4repl12C4SocketImplE#3}==> N8litecore4repl12C4SocketImplE ws://couchbase-gateway.dev.ims-mobile-data.ssaeim.prod.us.walmart.net:4984/salesfloor/_blipsync @0x70ca018cb0
{N8litecore4repl12C4SocketImplE#3} WebSocket closed abnormally with status 502

Posts: 2

Participants: 2

Read full topic

Delete document from server and client

$
0
0

@arorasurbhi93 wrote:

We have a requirement where if from one device , user deletes the document same thing should replicate to server and other clients. But as of now, delete is happening only in local database. how to achieve the same? TIA.

Posts: 1

Participants: 1

Read full topic

How to use admin REST API in xamarin application to create new users?

$
0
0

@Maria_Nabil1 wrote:

I am creating a xamarin mobile application and I want to create new users from the mobile application , I know I can create users from sync gateway configuration or from admin REST API ,
I tried to use the admin REST API in the application but I got Java.Net.SocketTimeoutException

so how can I use the admin REST API to create users in the application ?

Posts: 1

Participants: 1

Read full topic

Roku Support Phone Number

$
0
0

@Sophiya_Williams wrote:

The Roku Streaming device is a significantly more advantageous and practical intends to appreciate music, films, and so on. For getting a charge out of this streaming device, you should connect this streaming device your TV and interface with the web, set up a Roku records and endeavor to begin spilling your own top picks. On the off chance that you are one of the those who are using this streaming device and managing a couple of sorts of issues, you have to bring in our Roku Technical Support Number-(+1)-877-400-0903 that can be discovered all day, every day or even on gazetted occasions. They have long periods of mastery in taking care of an assortment of sorts of technical issues in a snappy time-span.

Posts: 1

Participants: 1

Read full topic

Index on existing database

$
0
0

@jasonwhetton wrote:

Hi,

I get an exception when trying to add an index to an existing couchbase lite database - with a File IO error.

Is this normal? Is it only possible to create indexes on new databases?

Thanks!

Posts: 2

Participants: 2

Read full topic

Console.log is not working on SG

$
0
0

@jejom43 wrote:

I would like to write the output of console.log in file.
I understand that the output of sync function is write in sg_info.log when a console.log function is discover.
But on SG 2.6, that’s not working (Linux Os).
anybody can help me?

Sync function :

“sync”: function (doc, oldDoc) { console.log("################# LOG TEST CONSOLE ######"); }

Logging configuration :

“logging”: {
“log_file_path”: “/var/log/sync_gateway”,
“console”: {
“log_keys”: [“HTTP+”, “Sync”, “SyncMsg”],
“log_level”: “debug”,
“color_enabled”: true
},
“info”: {
“enabled”: true
},
“debug”: {
“enabled”: true
}
}

Posts: 5

Participants: 2

Read full topic

Purging docs from CB cluster

$
0
0

@nkonstas wrote:

Hi everyone,

I plan to implement a cleanup service for our CB cluster and I want to make sure I’m doing this right.

Basically, we use CB for a mobile app and never done any purging. Due to the nature of our app CB nodes contain a lot of docs that can be purged. More specifically docs that only exist as children of other docs and no longer referenced by any parent docs.

My plan is to write a service that listens for CB changes and builds lists of docs that can be safely purged. All listening/ purging will be done via the SGs.

The reason we want to do this housekeeping server-side is to avoid bugs on individual platforms. Is that the right approach? Is there a better way to do this?

Also, I have two questions regarding purging docs:

  1. If a doc is purged and then a mobile device pushes a new rev for that doc, what will happen? is it just an error that will be ignored (i.e the rev will be ignored as the parent rev is missing) or will it affect further syncing in some other way?

  2. Server-side, are purges replicated across CB nodes? i.e. if I issue a purge request to a SG connected to a CB node, will other CB nodes (connected to their own SGs) receive it -or- do I have to issue the request on each one of the SGs for each of CB nodes?

Thank you!

Posts: 1

Participants: 1

Read full topic


Sync task seem to "block" UI thread on Android

$
0
0

@jda wrote:

I’m using CBLite 2.6.0, Community Edition 6.0.0 build 1693 and Couchbase Sync Gateway/2.6.0(127;b4c828d) CE.
Developing on Mac using Visual Studio 2019 - and Xamarin.Forms 4.4.0.xxxx (and same issue was on 4.3.0.yyyy)

I have developed an app that syncs with the server :slight_smile: - and when the sync. process is running on Android everything is very sluggish or non-responding. Once sync goes idle - everything starts working again. On iOS it just works smoothly…

I guess I must be doing something wrong in the way I start the replication task. But I have built it based on inputs from various examples and questions so I don’t really know what to do to fix this. In my service I have this method that I call on start:

        public async Task InitAsync()
    {
        var options = new DatabaseConfiguration();

        // Borrow this functionality from Couchbase Lite
        var defaultDirectory = Service.GetInstance<IDefaultDirectoryResolver>().DefaultDirectory();
        var dbFolder = Path.Combine(defaultDirectory, "data");
        if (!Directory.Exists(dbFolder))
        {
            Directory.CreateDirectory(dbFolder);
        }

        options.Directory = dbFolder;

        Logger.Debug($"Will open/create DB at path {dbFolder}");
        if (!Database.Exists(AppConstants.DB_NAME, dbFolder))
        {
            // Load prebuilt database to path
            await seedService.CopyDatabaseAsync(dbFolder);
            Db = new Database(AppConstants.DB_NAME, options);
            CreateDatabaseIndexes();
            Analytics.TrackEvent("Installed prebuilt database");

            //Db = new Database(AppConstants.DB_NAME, options);       // TODO: Reinstate prebuilt db once new version attached!
        }
        else
        {
            Db = new Database(AppConstants.DB_NAME, options);
        }

        // Database.SetLogLevel(Couchbase.Lite.Logging.LogDomain.Replicator, Couchbase.Lite.Logging.LogLevel.Debug);
        // Listen to events from app about going to sleep or wake up
        eventAggregator.GetEvent<OnBackgroundEvent>().Subscribe(HandleReplicator);
        eventAggregator.GetEvent<OnConnectivityEvent>().Subscribe(HandleReplicator);
        eventAggregator.GetEvent<OnLoginEvent>().Subscribe(RestartReplicator);
        eventAggregator.GetEvent<OnImagePushedEvent>().Subscribe(DisableReplication);
        AppUtils.LastReplication = null;

        StartReplicator();
        return;
    }

And this is the StartReplicator method:

void StartReplicator()
{
    AppUtils.ConnectionStatus = ReplicatorActivityLevel.Offline;
    if (null == Db)
    {
        Crashes.TrackError(null, new Dictionary<string, string> { { "StartReplicator", "Database not set!" } });
        throw new InvalidOperationException("Database not set!");
    }
    // Anonymous settings
    var username = AppUtils.AnonymousUserId;
    var password = AppUtils.AnonymousPassword;
    //var replType = ReplicatorType.Pull;           TODO: Should we revert to PULL?? - Pull-push avoids the crash error right now...
    var replType = ReplicatorType.PushAndPull;
    var channels = new[] { "!" };
    if (AppUtils.IsLoggedIn || AppUtils.ActivationPending)
    {
        username = AppUtils.UserId;
        password = AppUtils.Password;
        channels = new[] { "!", $"channel.{username}" };
        //replType = ReplicatorType.PushAndPull;    TODO: Reinstate if pull only above is reverted to
    }

    var dbUrl = new Uri(syncUrl, AppConstants.DB_NAME);
    Logger.Debug($"Start {replType} Replicator: Will connect to: {syncUrl} - user: '{username}'" + (AppUtils.ActivationPending ? " (activation pending!)" : ""));

    var config = new ReplicatorConfiguration(Db, new URLEndpoint(syncUrl))
    {
        ReplicatorType = replType,
        Continuous = true,
        Authenticator = new BasicAuthenticator(username, password),
        Channels = AppUtils.IsLoggedIn ? new[] { "!", $"channel.{username}" } : new[] { "!" }
    };

    config.PushFilter = (document, flags) =>
        {
            if (document.GetBoolean(nameof(BaseDoc.IsSyncDisabled).ToLower()))
            {
                Logger.Debug($"Pushfilter: Replication diabled for {document.Id}. Skip...");
                return false;
            }
            return true;
        };
    replicator = new Replicator(config);
    replListener = replicator.AddChangeListener((sender, args) =>
    {
        if (args is null) return;
        var s = args.Status;
        AppUtils.ConnectionStatus = s.Activity;
        Logger.Debug($"{replType} Replicator: {s.Progress.Completed}/{s.Progress.Total}{(string.IsNullOrEmpty(s.Error?.Message) ? "" : $", error {s.Error?.Message}")}, activity = {s.Activity}");
        if (!(s.Error is null))
        {
            if (s.Error is CouchbaseWebsocketException)
            {
                var cbex = s.Error as CouchbaseWebsocketException;
                if (CouchbaseLiteErrorType.CouchbaseLite.Equals(cbex?.Domain) && CouchbaseLiteError.HTTPAuthRequired.Equals(cbex?.Error))
                {
                    // If this is the anonymous user then we have a serious problem....
                    if (AppUtils.AnonymousUserId.Equals(username))
                    {
                        Crashes.TrackError(null, new Dictionary<string, string> { { "StartReplicator", $"User '{username}' with password: '{password}' cannot authenticate with server!!!" } });
                        Logger.Debug($"User '{username}' with password: '{password}' cannot authenticate with server!!! - Replication will not run");
                        StopReplicator();
                        return;
                    }
                    else
                    {
                        Logger.Debug($"Wrong credentials for user: {username}. Disable auto login...");
                        AppUtils.LoggedInTime = DateTime.MinValue;
                        AppUtils.Password = null;
                        // Retry start of replication without a logged in user - carefull here....!
                        StartReplicator();
                        return;
                    }
                }
            }
            Logger.Debug($"Error :: {s.Error}");
        }
        else if (s.Activity == ReplicatorActivityLevel.Idle)
        {
            AppUtils.LastReplication = DateTime.Now;
            if (s.Progress.Completed > 0)
            {
                eventAggregator.GetEvent<OnDataUpdateEvent>().Publish(true);
            }
        }
        eventAggregator.GetEvent<OnSyncStatusEvent>().Publish(s.Activity);
    });
    docListener = replicator.AddDocumentReplicationListener((sender, args) =>
    {
        // TODO: Consider checking docs (e.g. ispublic and userkey) to send more specific update events!!

        // Remove Image docs after they have been sent to the server. Images should be read from url's
        if (args.IsPush)
        {
            Logger.Debug($"Push replication finished sending {args.Documents.Count} documents");
            foreach (var document in args.Documents)
            {
                if (document.Error == null)
                {
                    Logger.Debug($"  Doc ID: {document.Id}" + (document.Flags.HasFlag(DocumentFlags.Deleted) ? " (deletion)" : "") + (document.Flags.HasFlag(DocumentFlags.AccessRemoved) ? " (access removed)" : ""));
                    if (!document.Flags.HasFlag(DocumentFlags.Deleted))
                    {
                        if (typeof(Image).Name.Equals(BaseDoc.GetTypeFromID(document.Id)))
                        {
                            eventAggregator.GetEvent<OnImagePushedEvent>().Publish(document.Id);
                        }
                    }
                }
                else
                {
                    Logger.Error($"  {(string.IsNullOrEmpty(document.Id) ? "" : $"Doc.id: {document.Id}, ")}Error: {document.Error}");
                }
            }
        }
        else
        {
            // TODO: Probably needs to be "silenced"/removed...
            Logger.Debug($"Pull replication finished receiving {args.Documents.Count} documents");
            foreach (var document in args.Documents)
            {
                if (document.Error == null)
                {
                    // Update User's full name in preferences if there is an update from the server.
                    if (AppUtils.IsLoggedIn && string.Equals(document.Id, BaseDoc.GetID(typeof(User).Name, AppUtils.UserId)))
                    {
                        var doc = Db.GetDocument(document.Id);
                        if (!(doc is null))
                        {
                            var user = doc.ToObject<User>();
                            AppUtils.UserFullName = user.AbbreviatedName;
                            Logger.Debug($"  Updated full name: {user.AbbreviatedName} in preferences for logged in user id: {AppUtils.UserId}");
                            if (user.Deleted)
                            {
                                AppUtils.StayLoggedIn = false;
                                AppUtils.Password = null;
                                AppUtils.LoggedInTime = DateTime.MinValue;
                                eventAggregator.GetEvent<OnLoginEvent>().Publish();
                            }
                        }
                    }
                    Logger.Debug($"  Doc ID: {document.Id}" + (document.Flags.HasFlag(DocumentFlags.Deleted) ? " (deletion)" : "") + (document.Flags.HasFlag(DocumentFlags.AccessRemoved) ? " (access removed)" : ""));
                }
                else
                {
                    Logger.Error($"  {(string.IsNullOrEmpty(document.Id) ? "" : $"Doc.id: {document.Id}, ")}Error: {document.Error}");
                }
            }
        }
    });
    replicator.Start();
}

Any suggestions or input is very much appreciated as the way it is running now is going to make Android people throw their phones to the ground…

Posts: 4

Participants: 3

Read full topic

Scoped storage of android 11 Scoped storage of android 11

$
0
0

@Bellathomas wrote:

One of the features that is going to be a part of android 11’s release is scope storage. It is going to have abilities to optimize the operating speed of memory reading and security. The applications will be able to overwrite files without needing the assistance of the user. You can simply say that this is one of the best android 11 features, especially since it makes extra space within devices proactively without requiring any assistance. However, the feature has been designed solely for the purpose of privacy and securing the devices and applications. How effective do you think this feature is going to be, are you excited to try it out?

Posts: 1

Participants: 1

Read full topic

Stop replication, then close/delete fails

$
0
0

@paulr wrote:

TLDR: If a user requests to delete all their data during a replication… I seem to be unable to stop the replication.

I set up my replication thus:

var target = new URLEndpoint(url);
var auth = new BasicAuthenticator(id, server_password);
var sync_config = new ReplicatorConfiguration(database, target)
{
   ReplicatorType = ReplicatorType.PushAndPull,
   Continuous = true,
   Authenticator = auth
};
replicator = new Replicator(sync_config);
listenerToken = replicator.AddChangeListener(SyncStatusUpdate);
replicator.Start();

If there is a lot of data to replicate, the replication runs happily, and I get the notifications.
However, during that replication, if the user selects “delete all my local data”, I want to stop replication and then delete the database.

I do it like this:

log.Debug("Stopping sync agent");
// Check if syncing hasn't even started yet.
if (replicator == null)
    return;
try
{
    replicator.Stop();
    replicator.RemoveChangeListener(listenerToken);
}
catch (Exception e)
{
    log.Error(e, "Failed to stop sync agent");
    // we need to keep going...
}
replicator = null;

I’m sure the exception is not being thrown - that is the stop seems to succeed.
I then wait a couple of seconds (elsewhere it was mentioned that things might take a couple of seconds to stop) before I start testing for the status == ReplicatorActivityLevel.Stopped. When this is true, I keep going. NOTE that I have extended this wait out to 20 seconds, but that doesn’t help.

Note that at this point, I am still receiving update events to my SyncStatusUpdate function. I shouldn’t be - but it is an indication that sync is not stopping.

Lastly I attempt to delete the database. I have tried Close then Delete, and Delete then Close. Both raise “please stop all replicators” errors. I have a “desperation” measure where I simply trash the files:

public void CloseAndDeleteDB()
{
    try
    {
        database.Delete();
        database.Close();
        database = null;
    }
    catch (Exception e)
    {
        log.Error(e, "Failed to delete database!");
        //  Lets try another route - by deleting it
        try
        {
            database.Close();
        }
        catch { }
        database = null;
        var dir = Path.Combine(path, config.DBName + ".cblite2");
        Directory.Delete(dir, true);
    }
    database = null;
}

A little later I create a fresh new database with no data, and my application then hangs.

So the question is… what else do I need to do to ensure replication stops, even when it is in the middle of a large replication, potentially with a lot of images (few MB in size).

Thx.
Paul

Posts: 3

Participants: 2

Read full topic

Getting information for rejected documents in push process

$
0
0

@glenn wrote:

Hi,

Is there a way to learn whether a document is rejected by sync gateway in cb lite side?

Let’s say we have a sync gw function which validates the json fields and the data that pushed from client is not valid. As a result, it is simply rejected. In this case, we may want to delete the invalid version of the document from cb lite db for that specific client. Is it possible to do that?

Thanks.

Posts: 12

Participants: 5

Read full topic

Slow creating new users/ channels

$
0
0

@nkonstas wrote:

Hi everyone,

we have a setup where every user gets it’s own channel (i.e. 1 user -> 1 channel) . Lately we noticed that creating new users & channels takes way too long (up to 30s). Is there anything we can do to correct this?

for reference this is how we create the user & assign a channel:

Dictionary<string, dynamic> createUserJson = new Dictionary<string, dynamic>() { { “password”, createUserData.password }, { “admin_channels”, new string[] { userId } } };
createUserData.result = AdminWebRequest(syncGateway, “PUT”, path, JsonConvert.SerializeObject(createUserJson), out statusCode);

Thank you.

Posts: 1

Participants: 1

Read full topic

Running Couchbase Sync Gateway instances in Kubernetes

Web Connection Closed By Peer

$
0
0

@utkarshshekhar wrote:

Code : 11001 MSG: Web Socket Connection closed by peer.
I’m getting this message while Push replication to the test drive provided by Couchbase server. I don’t know whether its a bug or something I’m missing in the code. I’m using the sample code provided by the Couchbase docs.
Docs link

Posts: 1

Participants: 1

Read full topic


How to check log from .cbllog files?

$
0
0

@itssrinadh wrote:

Hi,

I have a different types of .cbllog files and i want to check replications and other conflicts from .cbllog files by using cbl-log tool.

Can anyone please suggest, how to check the logs traces from .cbllog files?

Posts: 4

Participants: 2

Read full topic

How to configure the webhook to send just the document changes on the latest revision?

$
0
0

@dvdsenatore wrote:

This is my scenario so that the client is offline and update the document “n” times then when it’ll back online, on the server I would like to configure the webhook to send just the changes on the latest revision of that document , is this possible?

In case not from the .Net SDK there is a way to check if what the webhook sent to me is the latest version of the document? If yes how can I do it?

Any advice is more than welcome

Posts: 1

Participants: 1

Read full topic

Sync Gateway performance slowed to 1/20 previous speed

$
0
0

@DougWhitehead wrote:

I have a bucket with some 880K documents. Previously the initial sync was yielding about 1K docs per second. Since yesterday, the initial sync has been transferring about 50 docs/sec (maybe less). It is almost as if the default size dropped from hundreds down to tens per batch.

I am doing a pull sync. I have tested an old version of the client code, and it does not work at the previous speed. So I believe I/we somehow mucked up either the gateway config or the Couchbase behind it.

Is there wiki page somewhere that suggests what to look at when trying to speed up the sync?

Posts: 1

Participants: 1

Read full topic

Question about "empty" documents (tombstones?)

$
0
0

@jda wrote:

I have an app where I disable sync (by using a push filter that checks a field value on the document) for some types of documents recorded live - until the user finishes the recording. If the user cancels the whole recording then I delete the docs and that’s it.

Now, I have discovered that I have some “empty” documents in the database - and I just want to make sure that I’m not creating issues for myself (the solution is not in live production yet - with the app - the core web app is).

The meta data for a document could look like this: { "meta": { "id": "FishingTrip:4fe6b8e7faae456ab71bd4c0b73e8b93", "rev": "45-15ea0e7b241700000000000000000000", "expiration": 0, "flags": 0, "type": "json" }, "xattrs": { "_sync": { "rev": "2-99923b648e6b4b3d758da4f90dfbc6cffa5e9ad5", "flags": 1, "sequence": 144058, "recent_sequences": [ 144058 ], "history": { "revs": [ "2-99923b648e6b4b3d758da4f90dfbc6cffa5e9ad5", "1-29892e66d6e2bbcae6739d63e4ec251013225ce5" ], "parents": [ 1, -1 ], "deleted": [ 0 ], "channels": [ null, null ] }, "cas": "0x000017247b0eea15", "value_crc32c": "0x297bd0aa", "tombstoned_at": 1579090541, "time_saved": "2020-01-15T13:15:41.393098142+01:00" } } }
Is this just a tombstone waiting to be purged?

I have seen different values for the deleted field (0,1,2).

I guess I could avoid it if I do a db.purge(...) instead of a delete? The user could have created the data on the server as well - and if he deletes from the app it should obviously be a db.delete(...) instead. Not sure if I can query the document directly to know if it is an “existing” document or I’ll have to control that using my own “flag”?

Posts: 1

Participants: 1

Read full topic

What's new in CBLite 2.7?

$
0
0

@jda wrote:

Hi

I can see there is a new version 2.7 of CB Lite C# on NuGet :+1: :clap:

But before I update I would like to know what’s in the package… I have looked at the project page as stated in the NuGet package: https://github.com/couchbase/couchbase-lite-net/releases/tag/2.5.0 - the latest release there is 2.5.0… and there is a tag for version 2.6.4 (but more than a month old).

I then checked the documentation - but the latest version is 2.6: https://docs.couchbase.com/couchbase-lite/2.6/index.html

Is there anywhere I can see the updates - just to make sure that I can verify my code once updated?

Cc: @borrrden

Posts: 9

Participants: 3

Read full topic

Viewing all 1117 articles
Browse latest View live