Create a MongoDB Replica Set

Create 3 mongodb servers. Make sure update hosts files on all nodes or on DNS server

192.168.1.10 mongodb01
192.168.1.11 mongodb02
192.168.1.12 mongodb03
Read More

Backup LXD Container as Tarball

Backup

lxc snapshot <container name> backup
lxc publish <container name>/backup --alias <container name>-backup
lxc image export <container name>-backup lxd_<container name>_tarball
lxc image delete <container name>-backup
lxc delete <container name>/backup
Read More

Volatile Variable in Java

What is volatitle variable?

volatile variable in Java is a special variable which is used to signal threads, a compiler that this particular variables value are going to updated by multiple threads.

  1. Variable’s value is always read from main memory instead of cached value.
  2. Volatile variable guarantees “happens-before” relationship, which means not only another thread has visibility of latest value of volatile variable but also all the variable is seen by the thread which has updated value of volatile variable before these thread sees it.
Read More

Difference Between map and flatMap in Java 8

Definition in Java 8 Stream and Optional

Optional

  • map: If a value is present, apply the provided mapping function to it, and if the result is non-null, return an Optional describing the result. Otherwise return an empty Optional.
  • flatMap: If a value is present, apply the provided Optional-bearing mapping function to it, return that result, otherwise return an empty Optional. This Method is similar to map(Function), but the provided mapper is one whose result is already an Optional, and if invoked, flatMap does not wrap it with an additional Optional.
Read More

SSHFS on Centos

Install on machine which needs mount other folders only.

sudo yum install epel-release
sudo yum install fuse
sudo yum install sshfs
sudo modprobe fuse
Read More